1.11M Members

pagination ideas in php

 
0
 

ss i am creating a pagination on my page. i dont like pagination with numbers so i went with different one. take a look at my image that i upload. as you can see if user click at last button i want to load 8 more images.

to get data from database iam using this query:

$item_query = mysql_query("SELECT * FROM item ORDER BY RAND() LIMIT 8"); 

so i think i should use a variabler les say "$x" for '8'. that way if user click on the pagination i will can do this:

$x += 8;

i have never create a pagination before so if you think this is a bad idea let me know.

code is made of two part. 1st part is the display data.
2nd part is pagination button.
every thing is on one page.
full code:

<?php
  echo"
     <table>
        <tr'>
        ";

        /*** display images ***/
        $user_name_c = $_COOKIE['username'];
        $item_query = mysql_query("SELECT * FROM item ORDER BY RAND() LIMIT 8");  //--------remove random
        $count = 0;
        while($row = mysql_fetch_assoc($item_query))
        {   
            $image_user_name_db = $row['image_user_name'];
            $image_user_name_db = ucwords($image_user_name_db);   // upper case begining of every word
            $image_folder_name_db = $row['image_folder_name'];
            $price_db = $row['price'];
            $price_db = number_format($price_db, 2); //2 decimal. ex (1.0, 1)= 1.00

     echo"<td >";

    echo"<img src='http://localhost/E_COMMERCE/IMAGE/STORE_ITEMS_DB/$image_folder_name_db' width='150' height='150'/> <br/>";
    echo"<p id='name'>$image_user_name_db</p>";
    echo"<p id='price'>Our Price $$price_db</p>";

        echo "</td>";

        $count++;
         if($count == 4)       //4 cols
        {
            echo "</tr><tr>"; 
             $count = 0;
        }
    }//end of while loop


    echo"
      </tr>
        </table>
?>




///////////////////////////////
    /****** pagination **********/
    ///////////////////////////////
    echo"
            <button type='submit' id='load_button' class='button'>Load 8 more items</button> 
";
Attachments
 
1
 

Every time you click the more button you should increase a variable, and then multiply by 8, to use in the LIMIT clause. The first time would output:

<form action="?page=2">
<button type='submit' id='load_button' class='button'>Load 8 more items</button> 

Then you know to get 2 times the number of items. Each time increase this number. You can also store it in a session.

 
0
 

i end up changing some stuff. so every time user click on a link it will run the php code above. than run the new query.

so 1st there are 4 images. if user click on link onces, than it will show 8 images, if user click on link 2 times, it will show 12 images and so on...

the problem now is the value stay same bc i am setting it before query. so the variable value stay the same. not sure how can i fix this problem. if i remove $limit above query than it wont work bc 1st time when user dont click than limit should be set to 4.

<?php
if(isset($_GET['page'])) 
{
  $page_g= $_GET[page];
   $limit = 4;
  $offest = $limit * $page;
  $page++;  
}
...




...
$limit = 4;
$page = 1;
SELECT * FROM item ORDER BY id DESC LIMIT ($limit) OFFSET $offset");
...




///////////////////////////////
/****** pagination **********/
///////////////////////////////
echo" 
     <a href='index.php?page=$page'>Load 8 more items</a> 
   "; 
 
0
 

o got it to working

Question Answered as of 1 Year Ago by pritaeas
Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article