mysql error
Posted: Mon Sep 28, 2009 12:38 am
Code: Select all
<?php
if (isset($_GET['id'])){
include("mysql_connect.php");
$id = $_GET['id'];
echo "<a class=\"contentlinks\" href=\"create_topic.php?id=$id\">ADD</a>";
$sql = mysql_query("SELECT * FROM topics WHERE cat_id='".$id."'");
$total = mysql_num_rows($sql);
$page_rows = 4;
$last = ceil($total/$page_rows);
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * FROM topics where cat_id='".$id."' and $max") or die(mysql_error());
echo"<div class=\"mainbox\">";
$i=0;
while($row = mysql_fetch_array($data_p)) {
$i=$i+1;
if($i%2==0)
{
echo "<div class=\"one\"><a class=\"contentlinks\" href=location.php?id={$row['id']}>".htmlentities($row['title'])."</a></div>
<div class=\"two\">".htmlentities($row['post'])."</div>
<div class=\"third\"><a class=\"contentlinks\" href=location.php?id={$row['id']}>tutorial link</a></div>";
}
else
{
echo"<div class=\"oneone\"><a class=\"contentlinks\" href=location.php?id={$row['id']}>".htmlentities($row['title'])."</a></div>
<div class=\"twotwo\">".htmlentities($row['post'])."</div>
<div class=\"thirdthird\"><a class=\"contentlinks\" href=location.php?id={$row['id']}>tutorial link</a></div>";
}
}
echo"</div>";
if ($pagenum == 1)
{
}
else
{
echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pagenum=1&id=$id '> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pagenum=$previous&id=$id'> <-Previous</a> ";
}
//just a spacer
echo " ---- ";
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pagenum=$next&id=$id'>'>Next -></a> ";
echo " ";
echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pagenum=$last&id=$id'>'>Last ->></a> ";
}
mysql_close($con);
} else {
echo "invalid usage!";
}
?>hey in above code i am getting this
ADDYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 0,4' at line 1
after printing the first echo statement that is printing ADD.I USED AND TO COMBINE SELECT AND LIMIT FUNCTION.....where is the prob