Page 1 of 1

Pagination help..newbie!

Posted: Wed May 06, 2009 5:00 am
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!!

Re: Pagination help..newbie!

Posted: Wed May 06, 2009 4:15 pm
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 ).