Posted by Bill on 01/04/07 16:20
hi Hendri,
If I take the where clause out it works and returns all the records.
Tried numerious different combinations to try and put the where clause
in but still returns an error. Works ok using a sql statement in mysql.
Any other way to count records using where clause.
Thanks again for you time
bill
Bill wrote:
> Hendri Kurniawan wrote:
>> Query-ing mysql from PHP returned a "resource".
>> To get the actual result, use mysql_fetch_array (or similar functions).
>>
>> So:
>> $sqlcount = "SELECT count( lingo ) FROM `mainpage` WHERE lingo = \'en\'";
>> $resultRES = mysql_query ($sqlcount);
>> $resultcount = mysql_fetch_array($resultRES);
>> mysql_free($resultRES);
>> echo $resultcount[0];
>>
>> Hendri Kurniawan
>>
>> Bill wrote:
>>> Trying to count number of records in table and use result as a loop.
>>>
>>> in mysql I use
>>> SELECT count( lingo ) FROM `mainpage` WHERE lingo = 'en'
>>> I get the correct result of 35
>>>
>>> How do I use php to get same result and put result into a variable so
>>> that i can loop 35 times.
>>>
>>> I have tried
>>> $sqlcount = "SELECT count( lingo ) FROM `mainpage` WHERE lingo =
>>> \'en\'";
>>> $resultcount = mysql_query ($sqlcount);
>>> echo $resultcount;
>>> just to check that the number has been generated.
>>> But nothing is displayed. Is this the correct way to do this.
>>> Thanks in advance
>>>
>>> Bill
> Hi Hendri,
> I tried what you said and got the following error. The sql is only going
> to give one answer and I can see why you put the argument
> $resultcount[0]. Any other ideas on how to get the count. Thanks
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
> result resource
[Back to original message]
|