PDA

View Full Version : Specifying LIMIT for SQL DB using PHP


Mc Ghoush
Mon 13th Aug '01, 7:03am
I know that I asked a lot of questions, but i hope you will excuse me, learning a new programming language is not easy as you know ...

My new question is :

I wanted to spcify a limit for mySql Query using this statement ,

$sql_query = "SELECT * FROM gb1 order by id DESC LIMIT" . $start . "," . $end ;

But it didn't work ...

What shall i do to do that ??

Thanx ...

Mark Hensler
Mon 13th Aug '01, 11:08am
Use some code to report errors better...
This will make sure that your query returns a result. If it doesn't, this will print the error, and query. The stuff is printed in comment tags to keep it out of sight for visitors.

$sql_query = "SELECT * FROM gb1 order by id DESC LIMIT" . $start . "," . $end ;

$result = mysql_query($sql_query);
if (!$result) {
// something is wrong with the query
echo "\n<!--QUERY ERROR " . mysql_errno() . ":" . mysql_error() . "-->\n";
echo "\n<!--QUERY:$sql_query-->\n";
// do you want to halt the script?
// die();
}

Mc Ghoush
Tue 14th Aug '01, 12:51pm
I found the mistake ...

It was ".....LIMIT". $start

it supposed to be :
It was ".....LIMIT ". $start

It is a matter of a single space .....