开发者

Loading PHP file that loads records from a database which is already divided into pages

loading an external php file is cheap easy

   <html>
    <head>
    <script type="text/javascript" src="jquery-1.6.3.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        // load home page when the page loads
        $("#result").load("tablerecord.php");
    });
    </script>
    </head>


    <body>

    THE LIST

    <div id="result">
    </div>


    </body>

however....

 $maxsecCode = "SELECT * FROM t_board";
   $maxResult = mysql_query($maxsecCode);
   $maxRows = mysql_num_rows($maxResult);
   print "max rows is " . $maxRows . "<br>";
   $linkNum = ceil($maxRows/10开发者_Go百科);
   print $linkNum . "<br>";



   for ($i=1; $i<=$linkNum; $i++) { 
    echo "<a href='tablerecord.php?page=".$i."'>".$i."</a> "; 
   } 

the external php file loads records from a database, and divides the pages by 10, producing multiple links in the process.

if i click one of the pages i will be redirected to menu.php?page="whatever_page_i_clicked"!

i want to browse through the pages without leaving the main page.

is there any way to solve this problem?


If your number of records is less than a gazillion, it would be easier and cleaner to just retrieve all records, return them in a JSON string, and then use a paged table like datatables to show it.

EDIT: To turn a PHP object into a JSON string, just use json_encode() like this:

// some code to get your data into $myDataObject should go here, because
// you don't want to return the query result object; it's too bulky. Instead
// convert your result object to either a simple array of rows or fields, or into
// an object with fieldnames as attributes. Then...
$myJSONString = json_encode($myDataObject);
echo $myJSONString;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜