Pagination

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boliches
    New Member
    • Feb 2007
    • 62

    Pagination

    I am attempting to add script to limit the number of images displayed per page. The images to be displayed in 2 columns. The script I have used I obtained from searching "PHP Pagination" via Google, it seemed to work fine until I tried to added the code to put the images diplayed into 2 columns. Each set of code worked OK on its own! Any help would be appreciated.

    [CODE=php]
    <?php

    $Host="mysql1.n amesco.net";
    $User="usedcars gbco";
    $Password="0312 55";
    $DBName = "usedcarsgb co";
    $TableName = "VehicleSto ck";
    $TablePhoto = "cpg140_picture s";
    $Link = mysql_connect ($Host, $User, $Password);
    $Query = "SELECT * FROM VehicleStock LEFT JOIN cpg140_pictures ON VehicleStock.Re gNo = cpg140_pictures .title ORDER BY CarID DESC";
    $Result = mysql_db_query ($DBName, $Query, $Link);

    $max = 4;
    $p = $_GET['p'];
    if(empty($p))
    {
    $p = 1;
    }
    $limits = ($p - 1) * $max;
    //view the news article!
    if(isset($_GET['act']) && $_GET['act'] == "view")
    {
    $id = $_GET['RegNo'];
    $sql = mysql_query("SE LECT * FROM VehicleStock");
    while($r = mysql_fetch_arr ay($sql))
    {
    $RegNo = $r['RegNo'];
    $Price = $r['Price'];

    echo "<div><p>$RegNo </p><p>$Price</p></div>";
    }

    }else{


    $sql = mysql_query("SE LECT * FROM VehicleStock LIMIT ".$limits.",$ma x") or die(mysql_error ());
    $totalres = mysql_result(my sql_query("SELE CT COUNT(RegNo) AS tot FROM VehicleStock"), 0);
    $totalpages = ceil($totalres / $max);

    echo "<table align=center><t r><td>Reg No</td><td>Retail Price</td></tr><tr>";
    $_counter = -1;
    $_cols = 2;

    {
    $id = $r['RegNo'];
    $RegNo = $r['RegNo'];
    $Price = $r['Price'];
    //(NEXT 28 LINES OF SCRIPT DISPLAY IMAGES IN 2 COLUMNS)
    $_pos = ( ++$_counter % $_cols );
    if( $_pos === 0 )
    {
    echo '
    <tr>';
    }
    echo "<tr><td><a href='VehicleDe tail.php?act=vi ew&RegNo=$id&Pr ice=$Price'>
    <img border='0'alt=' Click for car details' src=gallery/albums/userpics/10001/$RegNo.jpg></a></td><td>£$Price</td>";
    }
    echo "</tr></table>";
    if( $_pos === $_cols - 1 )
    {
    echo '
    </tr>';
    }
    }

    if( $_counter % $_cols !== $_cols - 1 )
    {
    do
    {
    echo '
    <td style="visibili ty: hidden">&nbsp;</td>';
    }
    while( ++$_counter % $_cols !== $_cols - 1 );

    echo '
    </tr>';
    //END OF IMAGE DISPLAY SCRIPT
    }
    for($i = 1; $i <= $totalpages; $i++){

    echo "<a href='StockTest .php?p=$i'>$i</a>|";
    }


    ?>
    </body>
    </html>


    [/CODE]
    Last edited by Atli; Jun 11 '08, 10:47 PM. Reason: Fixed the [code] tags.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Let me get this right, you're wanting to display images in two columns?

    i.e:
    Code:
    img1 - img2
    img3 - img4
    img5 - img6
    
    // etc..
    Also, please remeber to use code tags properly when posting code.

    Comment

    • boliches
      New Member
      • Feb 2007
      • 62

      #3
      Yes thats correct!
      Also I did notice I missed a "]" , but it was too late to amend.

      Have been playing with my code and so far am unable to display just 4 images per page. But do have the links appearing to offer further pages! I feel I am close but that some of the code is in the wrong place. Your help would really be appreciated.

      Code:
      <?php
      
      $Host="mysql1.namesco.net";
      $User="usedcarsgbco";
      $Password="031255";
      $DBName = "usedcarsgbco";
      $TableName = "VehicleStock";
      $TablePhoto = "cpg140_pictures";
      $Link = mysql_connect ($Host, $User, $Password);
      $Query =  "SELECT * FROM VehicleStock LEFT JOIN cpg140_pictures ON VehicleStock.RegNo = cpg140_pictures.title ORDER BY CarID DESC"; 
      $Result = mysql_db_query ($DBName, $Query, $Link);
      $max = 4;
      $p = $_GET['p'];
      if(empty($p))
      {
      $p = 1;
      }
      $limits = ($p - 1) * $max;
      
      if(isset($_GET['act']) && $_GET['act'] == "view")
      {
      $id = $_GET['RegNo'];
      $sql = mysql_query("SELECT * FROM VehicleStock");
      while($r = mysql_fetch_array($sql))
      {
      $RegNo = $r['RegNo'];
      $Price = $r['Price'];
      }
      }else{
      $sql = mysql_query("SELECT * FROM VehicleStock LIMIT ".$limits.",$max") or die(mysql_error());
      $totalres = mysql_result(mysql_query("SELECT COUNT(RegNo) AS tot FROM VehicleStock"),0); 
      $totalpages = ceil($totalres / $max);
      }
      
      
      
      echo "<div><p>$RegNo</p><p>$Price</p></div>";
      
      
      for($i = 1; $i <= $totalpages; $i++){
      
      echo "<a href='StockTestAll1.php?p=$i'>$i</a>|";
      }
      
      echo '
      <table align=center>';
       
      $_counter = -1;  // We start 'outside' the Matrix.  Unlike Neo.
      $_cols = 2; // 3 columns.  Of the Ionic variety.
      while( $__row = mysql_fetch_assoc($Result) )
      {
          // Advance the counter and determine our 'position';
          $_pos = ( ++$_counter % $_cols );
       
          // Should we output a '<tr>'?
          if( $_pos === 0 )
      {
              echo '
              <tr>';
          }
       
              echo "
                
      <td><table>
      	<tr><td colspan=3 class='SLMakeModel'><b> &nbsp;{$__row['Make']}&nbsp;{$__row['Spec']}</b></td></tr>
      	
      	<tr><td><a href='VehicleDetail.php?RegNo=$__row[RegNo]&Price=$__row[Price]'>
              <img border='0'alt='Click for details' src=gallery/albums/$__row[filepath]$__row[filename] width='225' height='175'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a> 
      	<td valign='top'class='SLTransmissionText'><b>Registered:</b><br>{$__row['RegDate']}<br>&nbsp;<br>
      	<b>Transmission:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>{$__row['Box']}<br>&nbsp;<br>
      	<b>Mileage:</b><br>{$__row['Mileage']}<br>&nbsp;<br>
      	<b>Price:</b><br>£{$__row['Price']}
      	</tr> </td>
      
      	<Tr><td  colspan=3 class='SLMakeModel'><a href='VehicleDetail.php?RegNo=$__row[RegNo]&Price=$__row[Price]'><img border='0' alt='Click for Details'src=Images/details.gif> </a></td></tr>
      
      
      
      <tr> <td>
      	
      	
      </td></tr></table> 		</td>";
      
                      
       
          // Should we output a '</tr>'?
          if( $_pos === $_cols - 1 )
          {
              echo '
              </tr>';
          }
      }
      
      
      
      if( $_counter % $_cols !== $_cols - 1 )
      {
          do
          {
              echo '
                  <td style="visibility: hidden">&nbsp;</td>';
          }
          while( ++$_counter % $_cols !== $_cols - 1 );
       
          echo '
              </tr>';
      }
       
      echo '
      </table>';
      ?>

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by boliches
        Yes thats correct!
        Also I did notice I missed a "]" , but it was too late to amend.

        Have been playing with my code and so far am unable to display just 4 images per page. But do have the links appearing to offer further pages! I feel I am close but that some of the code is in the wrong place. Your help would really be appreciated.
        In fact, a few months back I had the same problem. Pbmods came up with a great solution. I'll just have to search the archives and find it!

        2 mins.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Here you go

          Hope it helps!

          Comment

          • boliches
            New Member
            • Feb 2007
            • 62

            #6
            Thanks for that, this is where I got my code from to limit the images per page. My problem from there was to create the links to the next 4 images etc. When I inserted the code to paginate I ended up with the links OK but lost the 4 images per page and got the whole array.

            The code (I think) is all there but must be in the wrong order. Any ideas?

            Comment

            Working...