Hi
I trying to implement pagination using LIMIT in MySQL. My problem is it works good for the first 3 results only and for later results it shows error saying check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 3, 3' at line 1 :-/
I couldnt get where i am going wrong here. Please look at my code below:
if($_GET["c"])
{ $k = $_GET["k"] ; $cnt = $k; $k = $k + 3; }
else
{$cnt = 0; $k = 3;}
$table = '<table >';
mysql_connect(" ") ;
mysql_select_db(" ");
$result = mysql_query("SELECT var1 FROM $tab1 LIMIT $cnt, 3") or die(mysql_error());
$i = 0;
while($row = mysql_fetch_array( $result ))
{
$var1 = $row['name'];
if ( $i == 3 ) {
$table .= '</tr><tr>';
$i = 0;
}
mysql_connect(" ") ;
mysql_select_db(" ");
$result1 = mysql_query("SELECT * FROM tab2 WHERE var2= '$var1'");
$row = mysql_fetch_array( $result1 );
$var2 = $row['var2'];
$table .= "<td > blah blah blah";
$i++;
}
$table .= "<tr><td ><a href=link.php?c=next&k=".$k.">next</a></td></tr>";
echo $table;
All the variables are retreived properly the only problem seems to be somewhere with LIMIT statement. Please let me know where am i going wrong.
Thank you in advance.