Pagination help..newbie!

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
david-remone123
Forum Newbie
Posts: 1
Joined: Wed May 06, 2009 4:53 am

Pagination help..newbie!

Post by david-remone123 »

Hi,

I'm really new to php and I am trying to learn it slowly. So far I have been able to create login/register scripts and can display my products all on one page. Now i want to split this page into several different pages, and Ive been using the following tutorial:

http://phpeasystep.com/phptu/29.html

In the last part where u enter your own while loop, i have:

Code: Select all

<?php
        while($row = mysql_fetch_array($result))
        {
    
        $result=mysql_query($query);
 
 
    $num=mysql_numrows($result);
 
 
    mysql_close();
 
    $i=0;
    while ($i < $num) {
 
    
    $product_name=mysql_result($result,$i,"product_name");
    $product_line=mysql_result($result,$i,"product_line");
    $product_description=mysql_result($result,$i,"product_description");
    $image=mysql_result($result,$i,"image");
    $price=mysql_result($result,$i,"price");
 
 
 
    echo "<font color=\"white\"><u>$product_name</u></b><br><br>$product_line<br><br></font>";
    echo "<img alt=\"product image\" width=\"250\" height=\"265\" src=\"images/".$image." \"/>";
    echo "<font color=\"white\"></br><u>Product Description</u><br><br>$product_description<br><br>£$price<hr><br></font>";
 
    $i++;
}
    
        }
    ?>

Then im getting these errors:

Code: Select all

 
Notice: Use of undefined constant num - assumed 'num' in C:\wamp\www\pagination.php on line 23
 
Notice: Undefined index: page in C:\wamp\www\pagination.php on line 28
 
Warning: mysql_result() [function.mysql-result]: product_name not found in MySQL result index 6 in C:\wamp\www\pagination.php on line 144
 
Warning: mysql_result() [function.mysql-result]: product_line not found in MySQL result index 6 in C:\wamp\www\pagination.php on line 145
 
Warning: mysql_result() [function.mysql-result]: product_description not found in MySQL result index 6 in C:\wamp\www\pagination.php on line 148
 
Warning: mysql_result() [function.mysql-result]: image not found in MySQL result index 6 in C:\wamp\www\pagination.php on line 150
 
Warning: mysql_result() [function.mysql-result]: price not found in MySQL result index 6 in C:\wamp\www\pagination.php on line 152
 


Can someone please tell me where im going wrong?

Many thanks for any help!!
Last edited by Benjamin on Wed May 06, 2009 12:04 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Re: Pagination help..newbie!

Post by Yossarian »

Code: Select all

 
       $result=mysql_query($query);
 
   while($row = mysql_fetch_array($result))
       {
 
It looks like you put the $result before the while () loop, can you see how I changed that bit?

You just pasted it wrong, you have error_reporting on which is good, but you need to start telling PHP to temporarily echo variables onto the page - so you work out where you are going wrong, debugging.

using var_dump() is what you need to start doing.

like var_dump( $result ) might have helped you zone in on what was going wrong, or var_dump( $row ).
Post Reply