You are here: Re: problem with limit command I think « All PHP « IT news, forums, messages
Re: problem with limit command I think

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация