|
Posted by J.O. Aho on 11/26/05 19:26
Julie wrote:
> I am trying to do this:
>
> $sql = "select * from names limit $startfrom,100";
>
> $result=mysql_query( $sql )
>
> I am trying to break up my query since the table is huge, so I increment
> $startfrom until it gets to the end of the query.
> But I am trying to test for $result returning false, but even with the limit
> way out of range and passed the end, it always returns something
> like Resource id #14. How can I test to see if the query is done:
When mysql_query() returns false, then there was something that went wrong
with the query, so you should run mysql_error() to get the error in question
eg:
$sql = "select * from names limit $startfrom,100";
if(!$result=mysql_query( $sql )) {
echo mysql_error();
}
If you get "Resource id #14" or something similar (the number may be
different), then the query was okey, if you want to access the data from the
query, then you need to fetch it, mysql_fetch_array() is a quite command.
eg:
$sql = "select * from names limit $startfrom,100";
if(!$result=mysql_query( $sql )) {
echo mysql_error();
}
while($row=mysql_fetch_array($result)) {
print_r($row);
}
IMHO it's good to print out the query when you are getting troubles, this will
help you to see what may go wrong, and in your case I think it's that
$startfrom don't have any value.
eg:
$sql = "select * from names limit $startfrom,100";
echo $sql; //results most likely in: select * from names limit ,100
if(!$result=mysql_query( $sql )) {
echo mysql_error();
}
while($row=mysql_fetch_array($result)) {
print_r($row);
}
Have fun...
//Aho
[Back to original message]
|