1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Rep Power

    thanks so far for your input. Now I'm trying to order my output (tables of DB) into pages that means let's say after 10 rows I want to have a new page which I want to select by clicking on the page number.
    Thank you very much.

  2. #2
  3. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    this is a lot fun..

    You can do this a few different ways, this is pretty much how I do it.

    my sql statement uses the LIMIT pos,limit

    You need to make the the pos a variable, naturally your first request sets the value of post to 0, and you can set the limit to the number of results you want on a single page, like say 30.

    sql will output your results, then you need to have PHP create a link, to call the next X records, from your query.

    here's a working example of what I use.

    $limit = 30;
    if ($pos == "") {
    $pos = 0;

    $sql_result = "SELECT * FROM customers";
    $count_result = mysql_query($sql_result);
    $num = mysql_numrows($count_result);
    $sql_result = "SELECT customer_id,account_num,company_name,host_acct,status,isp_email FROM customers";

    if (!$order) { $orderby = "ORDER BY customer_id ASC"; }
    else {
    if ($order == "account_num") { $orderby = "ORDER BY ".$order." ASC"; }
    else { $orderby = "ORDER BY ".$order.",account_num ASC"; }

    $result = mysql_query($sql_result.=" $orderby LIMIT $pos,$limit");

    echo "my table starts heren";

    $i = 0;
    while($myrow = mysql_fetch_array($result)) {
    $x = $myrow[0];
    $y = $myrow[1];
    $z = $myrow[2];

    echo "";

    //display a "back/next" based on number of rows in the query.
    echo "<tr>n";
    echo "<td colspan="8" align="center">";

    $pos_next = $pos + $limit;
    $pos_prev = $pos - $limit;
    $end = $num - $limit;

    if (($num > $limit) && ($pos < $num)) {
    if ($order) { $orderAd = "&order=$order"; }
    echo "<a href="$PHP_SELF?list=yes".$orderAd."&pos=0" class="links"><< Begin</a>&nbsp;&nbsp;";

    if ($pos >= $limit) {
    echo "<a href="$PHP_SELF?list=yes".$orderAd."&pos=$pos_prev" class="links">< Previous</a>&nbsp;&nbsp;";

    if ($pos + $limit < $num) {
    echo "<a href="$PHP_SELF?list=yes".$orderAd."&pos=$pos_next" class="links">Next ></a>&nbsp;&nbsp;";
    echo "<a href="$PHP_SELF?list=yes".$orderAd."&pos=$end" class="links">End >></a>&nbsp;&nbsp;";

    echo "</td>";
    echo "</tr>n</table>n";

    This example also offers the use a way to "alter" the ORDER BY of the results, hence the $orderAd variable, you'll notice how we pass the $pos variable.

    I hope this helps to answer your question.

    SnR Graphics,
    Low Cost Hosting and Web Development.

Similar Threads

  1. urgent: problem + output filters
    By jackjenas in forum Apache Development
    Replies: 2
    Last Post: May 27th, 2004, 07:39 AM
  2. combing three pages into one
    By thindery in forum PHP Development
    Replies: 1
    Last Post: February 14th, 2004, 06:07 PM
  3. how to speed up local apache/php in processing pages?
    By mickeyren in forum Apache Development
    Replies: 0
    Last Post: January 20th, 2004, 12:11 AM
  4. Perl Newbie: grabbing output of an ext. file
    By x-coder in forum Perl Programming
    Replies: 9
    Last Post: November 13th, 2003, 03:29 AM
  5. No price output from my script???
    By Charlie in forum Perl Programming
    Replies: 8
    Last Post: November 12th, 2003, 01:38 PM

IMN logo majestic logo threadwatch logo seochat tools logo