php - limited number of rows in a page -


hi i'm retrieving data db data (pic & name ) when retrieved them put them in 4 columns wanna limit number of rows in each page , want each page shows 3 rows , if there more data want make display in next page

my code :

    <?php $items_in_row = 4 ; $index = 0 ; ?>  <table>   <tr>  <?php while ($row = mysql_fetch_array( $result , mysql_assoc)){    $index++ ; ?>   <td>            <p>       <img id='g1' src='/<?php echo $row["img"] ;?>' width=130 height=130 onclick='f1()'>     </p>     <p> name: <?php echo $row['name'] ; ?> </p>     <br>   </td> <?php if ($index%$items_in_row == 0){ ?>   </tr>   <tr> <?php } } ?> </tr> </table> 

one way use limit() function in sql, passing in variables storing in session in php. let's want 3 rows of 4 pictures on each page, want 12 pictures. like

select * pictures limit(0,12) 

this returns first 12 items.

you can tracking page number. maybe have $page variable in php. if on page 2, $page contains 2. use construct dynamic sql query php maybe this...

$sqlquerystatement = "select * pictures limit(". ($page-1)*12 . ", 12)"; 

what page 2, produces sql statement:

select * pictures limit(12,12) 

see how works? execute sql, , have set of results should output page 2.

you can use further logic take these basic concepts , run them...extending them uses creating clickable pagination numbers on bottom of results , forth.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -