Results 1 to 9 of 9

Thread: PHP Question

  1. #1
    Join Date
    May 2004
    Posts
    84

    PHP Question

    Good morning, noon, or night. I'm in the process of building a website with PHP and a mySQL database backend. Here is my question:

    If I'm pulling info out of a database with
    $result=mysql("$DBName","SELECT * FROM Items WHERE Category='$CA' ORDER BY ItemName");

    and creating an array with the rows to assign variables so that I can display the info in my chosen format.

    How would I then go about splitting the info up if the records exceeded a given amount. Like having a little clickable 1, 2, 3, in the bottom corner so that the display page doesn't end up way too long if there are lots of records in the table. I'm guessing I would create an if statement whereby rows exceeding a specified total would be displayed on a second page but I'm not sure how the links would work and what the functions would look like. Please assist if you are able. Thanks.

  2. #2
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,345
    you will have to use the mysql_fetch_array, then the subscript will be accordingly with those in data base (e.g. if userid if first fild, subscript 0 will be the userid and so on)

    PHP Code:
    //This if you only have one record you want to display
    $split_rows = @mysql_fetch_array($result);

    //Displaying all records

    while( $split_rows = @mysql_fetch_array($result))){
    echo 
    'userid is: ' $split_rows[0];
    echo 
    'name is:' $split_rows[1];
    echo 
    'email is:' $split_rows[2];

    // You get the picture and so on..


    Salam,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  3. #3
    Join Date
    Jan 2003
    Posts
    1,715
    I think he means record count / page numbering.

    Look up the 'LIMIT' clause in the MySQL docs. You may also want to use the COUNT(*) function to determine how many pages of results you have.
    Game Servers are the next hot market!
    Slim margins, heavy support, fickle customers, and moronic suppliers!
    Start your own today!

  4. #4
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,345


    sometimes I do read too fast ...lol

    On top of page

    PHP Code:
    if(isset($_GET['np'])) {
        
    $num_pages $_GET['np'];
    } else {
        
    $query "SELECT * FROM listings WHERE `list_id`='$scat'";
        
    $query_result mysql_query($query);
        
    $num_records mysql_num_rows($query_result);
            if(
    $num_records $display) {
                
    $num_pages ceil ($num_records/$display);
            } else {
                
    $num_pages 1;
            }
    }

    if(isset(
    $_GET['s'])){
        
    $start $_GET['s'];
    } else {
        
    $start 0;
    }
    $query "SELECT * FROM listings WHERE `list_id`='$scat' ORDER BY  list_title ASC LIMIT $start,$display";
        
    $query_result mysql_query($query);
    $countmysql_num_rows($result); 
    Then where u want the numbers to appear:
    PHP Code:
    f($count $display){
                        echo 
    '<p align="center">';
                        
    $current_page = ($start/$display)+1;
                            if(
    $current_page != 1) {
                                echo 
    '<a href="showscat.php?scat=' $scat '&s=' . ($start-$display) . '&np=' $num_pages '" class="link" onmouseover="return vprev()" onmouseout="return clearit()">Previous</a>';
                            }
                        for (
    $i 1$i <= $num_pages $i++) {
                            if(
    $i != $current_page){
                                echo 
    ' [<a href="showscat.php?scat=' $scat '&s=' . (($display * ($i 1))) . '&np=' $num_pages '" class="link" onmouseover="return vpage()" onmouseout="return clearit()">' $i '</a>] ';    
                            } else {
                                echo 
    '<font color="gray"> [' $i '] </font>';
                            }
                        }
                        if(
    $current_page != $num_pages){
                            echo  
    '<a href="showscat.php?scat=' $scat '&s=' . ($start+$display) . '&np=' $num_pages '" class="link" onmouseover="return vnext()" onmouseout="return clearit()" >Next</a>';
                        }                        
                        echo 
    '</p>';
                    } 
    The $display contains the number of how many records u want to view..

    edit the above based on ur specisfcation

    salam,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  5. #5
    Join Date
    May 2004
    Posts
    84
    Hey Thanks a million for your help! I really appreciate it.

  6. #6
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,345
    $20 bucks :p
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  7. #7
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,104
    You can also get (for free) the PEAR:B_Pager class which does this and a whole lot of other things.

  8. #8
    Originally posted by azizny
    $20 bucks :p
    how about a kick in da nuts?

  9. #9
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,345
    Originally posted by shraz
    how about a kick in da nuts?
    No... Its ok..

    I'll stick to the 20 bucks
    Testing 1.. Testing 1..2.. Testing 1..2..3...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •