简体   繁体   中英

ShowMore Button for PHP-mySQL generated table

<?php
 $nrows = mysqli_num_rows($result);
  for (;$i<$nrows;)
   {                        
    echo"<tr>";
    for ($j=0;$j<10&&$i<=$nrows;$j++)
    {
    $n = $i;
    $i=$i + 1;
    $k=$n%30;
    $row = mysqli_fetch_assoc($result);
    extract($row);
    echo "<td><table  width='100%' id=$Code>
                    <tr><td>$Code</td></tr>
                    <tr><td>$Name</td></tr>
                </table></td>"; 
    if ($k==0)break 2;

 }
 echo"</tr>";
}
?>

This is simple code for a sample table that i am working on. It being called in external file with $nrows and $i defined produces 10*3 table of 30 results. And called twice 60 results and so on.

I wish to add a showmore button to call this file. I worked around with div and ajax

I got pagination script and tried to work with it and added this button to it. and tried to get next page with ajax.

if ($currentpage != $totalpages) {                                                     
echo"<p><div id='more'><input name='ShowMore' type='button' id='$nextpage' onclick='showmore(this.id)'  value='ShowMore' /></div></p>";}

The problem with this button is that it work good just First page is there while after that for every click next page appears but in place of other page.

I know problem is with div id which is constant. Is there any way to change it everytime one click on showmore. I am also this thinking to work with mysql limit but unable to find a way to pass it to next table.

Any sort of help is welcome. Thanx in Advance.

您能否制作一个javascript onClick函数来更改div的ID并将其放在显示更多链接上?

well i finally devised a crude method. though I would not recommend anyone else to use it but it works perfectly. I have defined two different variable one in AJAX call and another in php script. and I increase them by one on each call. just because of simple mathematics of 1=1 and 2=2 . It works perfectly. I am still looking for refined answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM