Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Paginated Data using PHP & MySQL

    Hi All,

    Hoping someone can help me out with this, I have a products database and the data pulled and displayed on a paginated page..However currently the data is just listed in 3 columns "Product_Image" "Model_No" & "Product PDF", But i want to change it so it is more like a catalogue and has 3 -4 products in row rather than listing them in all in one column. The code to display the data and link to example page is below:

    PHP Code:
          echo "<tr><th>Product Image</th><th>Model No</th><th>Product PDF</th></tr>";   
     
            
    // loop through results of database query, displaying them in the table  
            
    for ($i $start$i $end$i++) 
            { 
                    
    // make sure that PHP doesn't try to show results that don't exist 
                    
    if ($i == $total_results) { break; } 
             
                    
    // echo out the contents of each row into a table 
                    
    echo "<tr>"
                    echo 
    '<td><img src="' mysql_result($result$i'product_image') . '"/></td>'
                    echo 
    '<td>' mysql_result($result$i'model_no') . '</td>'
                    echo 
    "<td><a href='" mysql_result($result$i,'product_pdf') . "'>Product PDF Download</a></td>";  

                    echo 
    "</tr>";  
            } 
            
    // close table> 
            
    echo "</table>";  
             
            
    // pagination 
    http://upun.co.uk/UKJST.php

    hope this makes sense, and appreciate any input on the matter!

    Thanks,

    Steve

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,538
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    I would probably use <div> and stylesheet (CSS) to create a widget
    for each item, but you're using <table>, which is OK because you're
    displaying tabular things. I didn't specify any styling for the <td>
    tags (width, spacing, etc). I just wanted to see if the layout works.

    PHP Code:


    echo "<tr>";
    $count=0;

            
    // loop through results of database query, displaying them in the table   
            
    for ($i $start$i $end$i++)  
            {  
                    
    // make sure that PHP doesn't try to show results that don't exist  
                    
    if ($i == $total_results) { break; }  
              
                    
    // echo out the contents of each row into a table  
    if($count==3){
    echo 
    "</tr><tr>";
    $count=0;
    }
    $model=mysql_result($result$i'model_no');
                    echo 
    "<td><img src=" mysql_result($result$i'product_image') . " alt='" $model "' title='" $model "' /><br />";  
                    echo 
    "<b>Model: </b>" $model "<br />";  
                    echo 
    "<a href='" mysql_result($result$i,'product_pdf') . "'>Product PDF Download</a></td>"
      
    $count++;
            }  
    echo 
    "</tr>";
            
    // close table>  
            
    echo "</table>";   
              
            
    // pagination 
    Last edited by mlseim; 08-10-2012 at 05:10 PM.

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Mlseim,

    thanks for the input, it is working with an issue, have put a test page up for you to see, As you can see where the image is meant to be there is the model no again,

    Any ideas? i tried a few couple adjustments but just get the image url appearing,

    http://upun.co.uk/UKJST1.php


    Thanks,

  • #4
    New Coder
    Join Date
    May 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    managed to fix the bug mate,

    PHP Code:
     echo "<tr>";
    $count=0;

            
    // loop through results of database query, displaying them in the table   
            
    for ($i $start$i $end$i++)  
            {  
                    
    // make sure that PHP doesn't try to show results that don't exist  
                    
    if ($i == $total_results) { break; }  
              
                    
    // echo out the contents of each row into a table  
    if($count==3){
    echo 
    "</tr><tr>";
    $count=0;
    }

    $model=mysql_result($result$i'model_no');
          echo 
    '<td><img src="' mysql_result($result$i'product_image') . '"/><br />';  
          echo 
    "<b>Model: </b>" $model "<br />";  
          echo 
    "<a href='" mysql_result($result$i,'product_pdf') . "'>Product PDF Download</a></td>"
      
    $count++;
            }  
    echo 
    "</tr>";
            
    // close table>  
            
    echo "</table>";   
              
            
    // pagination 
    many thanks again

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,538
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    If you make your left and right page columns narrower, and make the
    middle column wider, you'll get better "white space" between items and
    the model numbers would be wrapped.

    My "alt" and "title" properties were supposed to create the model number in
    the mouse-over "tip box" when you hover over the image. I must
    have made a typo ... but a "tip box" was the intent of it.

    Glad you got it working.

  • #6
    New Coder
    Join Date
    May 2012
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah works fine now, thanks again, WIll work on the margins after i update the rest of the pages, making changes as i go through it but the products were the main concern as they are the biggest job of it really


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •