Jump to content

[SOLVED] Pagination error


timmah1

Recommended Posts

Can anybody tell me why I'm getting this error?

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10,10' at line 1

 

This worked just fine, but now I"m getting an error.

Could it be because nothing is in the database?

 

<?php
include('config.php');

if (!(isset($_GET['pagenum'])))
{
$pagenum = 1;
}

$data = mysql_query("SELECT * FROM wishlist") or die(mysql_error());
$rows = mysql_num_rows($data);

$page_rows = 10;
$last = ceil($rows/$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 wishlist $max") or die(mysql_error());
while($p = mysql_fetch_array( $data_p ))
{
$content = stripslashes($p['content']);
			$item = $p['item'];	
			$site = $p['site'];	
			$price = $p['price'];	
			$photo = $p['photo'];
			$name = $p['name'];

		?>
            <p class="text-content">
            <table border="0" cellspacing="0" cellpadding="6" class="text">
              <tr>
                <td align="left" valign="top"><span class="user_info"><strong><?=$name;?></strong> on <i>#<?=$item?></i></span></td>
              </tr>
              <tr>
                <td align="left" valign="top"><span class="posts"><img src="wish/<?=$photo;?>" width="100" class="photoID" align="left" /><?=nl2br($comment);?></span></td>
              </tr>
            </table>
            <?php
}
if ($pagenum == 1)
{
}
else
{
echo " <a href='test1.php?pagenum=1'> <<-</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='test1.php?pagenum=$previous'> <-</a> ";
}
echo "Page $pagenum of $last ";

if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='test1.php?pagenum=$next'>-></a> ";
echo " ";
echo " <a href='test1.php?pagenum=$last'>->></a> ";
}
?> 

 

Thanks in advance

Link to comment
Share on other sites

Thanks ober, but I fixed it.

 

I was trying to get the $page_rows with nothing to show

I just added an if statement

$data = mysql_query("SELECT * FROM wishlist") or die(mysql_error());
$rows = mysql_num_rows($data);
if($numrows == 0){
echo "<font color='#c60001'>No Items As Of Yet</font>";
} 

 

and it fixed the problem

 

Thank you

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.