SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    New Zealand
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    counting rows and seperating into pages.

    Hi

    Can anyone suggest how I can take the results of a query and split it up into pages.. eg, on this page that displays art work, the page is going to get to big and require a lot of scrolling. It would look better and be more user-friendly if it was split up.

    Here is the php file:
    PHP Code:
    <ul class="addworklist">
    <?php

    $works 
    = @mysql_query('SELECT name, aid, ref, title, image FROM works, artist WHERE aid = artist.id ');
    if (!
    $works) {
      exit(
    '<p>Error retrieving categories from database!<br />'.
          
    'Error: ' mysql_error(). '</p>');
    }

    while (
    $gallery mysql_fetch_array($works)) {
      
    $ref $gallery['ref'];
        
    $title $gallery['title'];
        
    $image = ($gallery['image']);
        
    $name $gallery['name'];
      echo 
    "<li><p class='galtext'></p> ".
                 
    "<a href='enquiry.php?ref=$ref'><img src='images/thumbnail/tn_$image' alt='$title' class='tdimg' /></a> ".
           
    "<p class='galtext'>$name</p></li> ";

    }

    ?>

    Thanks

  2. #2
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are going to have to look into pagination

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    New Zealand
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by klik
    You are going to have to look into pagination
    I've read the tutorial from the Reverend on Pagination and butchered it trying to get it to work in this script:
    PHP Code:
    <?php

       $dbcnx 
    mysql_connect ('localhost''username''password') or die ('I cannot connect to the database because: ' mysql_error());
    mysql_select_db ("database");

       
    $limit          15;               
       
    $query_count    "SELECT count(*) FROM works";    
       
    $result_count   mysql_query($query_count);    
       
    $totalrows      mysql_num_rows($result_count);

    if(empty(
    $page)){
       
    $page 1;
    }
            
       
    $limitvalue $page $limit - ($limit);

    $works = @mysql_query('SELECT name, aid, ref, title, image FROM works, artist WHERE aid = artist.id ');
    $query  "SELECT * FROM works LIMIT $limitvalue$limit"
    if (!
    $works) {
      exit(
    '<p>Error retrieving works from database!<br />'.
          
    'Error: ' mysql_error(). '</p>');
    }

    if(
    mysql_num_rows($works) == 0){
            echo(
    "Nothing to Display!");
    }

    while (
    $gallery mysql_fetch_array($works)) {
      
    $ref $gallery['ref'];
        
    $title $gallery['title'];
        
    $image = ($gallery['image']);
        
    $name $gallery['name'];
      echo 
    "<ul class='addworklist'><li><p class='galtext'></p> ".
                 
    "<a href='enquiry.php?ref=$ref'><img src='images/thumbnail/tn_$image' alt='$title' class='tdimg' /></a> ".
           
    "<p class='galtext'>$name</p></li></ul> ";

    }

    if(
    $page != 1){
       
    $pageprev $page--;
      echo(
    "<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");
    }else{
      echo(
    "PREV".$limit." ");
    }

    $numofpages $totalrows $limit;
    for(
    $i 1$i <= $numofpages$i++){
    if(
    $i == $page){
      echo(
    $i." ");
    }else{
      echo(
    "<a href=\"$PHP_SELF?page=$i\">$i</a> ");
    }
    }

    if((
    $totalrows $limit) != 0){
    if(
    $i == $page){
      echo(
    $i." ");
    }else{
      echo(
    "<a href=\"$PHP_SELF?page=$i\">$i</a> ");
    }
    }

    if((
    $totalrows - ($limit $page)) > 0){
        
    $pagenext $page++;
      echo(
    "<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
    }else{
      echo(
    "NEXT".$limit);
    }
        
    mysql_free_result($result);

    ?>
    the output can be seen here in the gallery.

    Any suggestions?

    Thanks

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    New Zealand
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any ideas on the above issue?

    Thanks


Bookmarks

Posting Permissions

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