0

how i can paginating unlimited data from My sql , if i want to use the limit , i must know the number of rows, but i don't know the number of rows.

this is the code for getting data from the database :

<?php 
$accid = $_SESSION['accid'];


set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] . "bulk2/" );
include("/config.php");

$con = mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
mysql_query("SET CHARACTER SET utf8");


$res=mysql_query("SELECT * FROM `sent_msgs_history` WHERE `accid` = $accid" ***LIMIT 0,5*** );
if(mysql_num_rows($res)> 0)
{
    for($i=0;$i<mysql_num_rows($res);$i++) {
        $row=mysql_fetch_assoc($res);
        //$de_name = decrypt($key,$iv,$row['rec_name']);
        //$de_mobile = decrypt($key,$iv,$row['mobile_number']);

        $de_name = $row['senderName'];
        $de_length = $row['MessageLength'];
        $de_count = $row['MessageCount'];
        $de_date = $row['sent_on'];
        $de_sender = $row['sent_by'];
        ?>


  <tr>

  <td> <?php echo $de_name ;?>    </td>
  <td> <?php echo $de_length;?>    </td>
  <td> <?php echo $de_count;?>    </td>
  <td> <?php echo $de_sender;?>    </td>
  <td> <?php echo $de_date;?>    </td>
  </tr>






  <?php }?>


  </table> 
  <br> 

 <br><br> <br>


<?php
 }?> 

i don't know the number of row , how can i do that ????? please help me >>>

Sereen
  • 39
  • 1
  • 3
  • 8
  • if i have more than thousand row,unlimited rows , how can i know the number of bages that i should use ????? – Sereen Mar 26 '14 at 09:48

3 Answers3

1

Similar / same question - MySQL skip first 10 results
Or to get all results after an offset - MySQL skip first 10 results

The LIMIT just needs to be from what ever items_per_page to the items_per_page * last_index

So something like:

SELECT * FROM sent_msgs_history LIMIT items_per_page, items_per_page * lastindex

So when getting 40 items per page:

page 1 would be LIMIT 40
page 2 would be LIMIT 40, 40
page 3 would be LIMIT 40, 80

Community
  • 1
  • 1
dan richardson
  • 3,871
  • 4
  • 31
  • 38
  • if i have more than thousand row,unlimited rows , how can i know the number of bages that i should use ?? – Sereen Mar 26 '14 at 09:59
  • Do you mean number of page buttons in the pagination? You wouldn't show them all. Something like this is what you'd be looking for - http://patternry.com/p=search-pagination/ - You can always do a single count of all rows and store that to calculate the number of page buttons you will need – dan richardson Mar 26 '14 at 10:20
0

What you mean unlimited pagination?

If you wish to know rows count, SELECT COUNT(*) FROM sent_msgs_history

OR

Don't use limit, when user selects "unlimited pagination"

Justinas
  • 41,402
  • 5
  • 66
  • 96
0

New

Use a loop with your desired limit range and then use this on the end of query. as (simple pagination)

$limit='';
$i=0; 
$q=mysql_query(...)
while($i<=mysql_num_rows($q))
{
$b=$i+5;
$limit='limit '.$i.', '.$b;
mysql_query(...$limit)
}
Teerath Kumar
  • 488
  • 5
  • 15