mysql error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

mysql error

Post by mayanktalwar1988 »

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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mysql error

Post by requinix »

Code: Select all

$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());
Wrong syntax. LIMIT is not a condition, it's a separate part of the query.

Code: Select all

SELECT ... FROM ... WHERE ... LIMIT x, y
Last edited by requinix on Mon Sep 28, 2009 2:08 am, edited 1 time in total.
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: mysql error

Post by mayanktalwar1988 »

ok
mayanktalwar1988
Forum Contributor
Posts: 133
Joined: Wed Jul 08, 2009 2:44 am

Re: mysql error

Post by mayanktalwar1988 »

hey after correcting the above asked error
the first echo statement is printing ADD____.add follwed by four underscores
BUT NOT SIMPLY ADD
i havnt seen something like this before whats this
Post Reply