Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    limit with php script

    hi how are you doing?

    What I am doing is that my database is so big so that I would like to show my results 5 each. Let's say I have 20 pictures in my database. Then I would like to show up 5 pictures in each page. It will be 4 pages. First page 5 pictures then when I click Next link,it goes to Next page which is 2page(6-10pic).3page(11-15 pic) and 4page(16-20pic).

    I tried my scritp but it doesn't work at all

    Here is script. my php is 4.23
    PHP Code:

    <?php 
    if(!isset($_POST['searchtype']) || !isset($_POST['searchterm']))  
    {   
    echo
    "you have not entered search details. Please go back and try again.";   
      exit;   

    else 

      
    $searchtype $_POST["searchtype"];  
      
    $searchterm $_POST["searchterm"];  
    }
      
    trim($searchterm); 

      
    $dbconnect mysql_connect("localhost""itohideo_hide""0810"); 
      if (!
    $dbconnect) { 
        echo( 
    "<p>Unable to connect to the " 
              
    "database server at this time.</p>" ); 
        exit(); 
      } 

      if (! 
    mysql_select_db("itohideo_japan") ) { 
        echo( 
    "<p>Unable to locate the host " 
              
    "database at this time.</p>" ); 
        exit(); 
      } 
       
       
    $PHP_SELF $_SERVER["SCRIPT_NAME"];

       
       if(
    $searchterm==""){
       
       exit(
    "You should specify your request<a href=\"lookforgirl.html\">Go Back</a>");
       
       }
       
       else{
      
    $sql "SELECT * FROM girls WHERE " $searchtype " LIKE '%" $searchterm "%'";  
      
    $result mysql_query($sql);  
      
    $num_results mysql_num_rows($result); 
    if (isset(
    $_GET["page"]))
    {
    $page $_GET["page"];
    }
    else {
    $page 1;
    }

    if(
    $page>10)
    {
    $page 10;

    }
      print(
    $page."Page<br><br>\n");
      echo(
    "<p>itohideo.com found: " $num_results "</p>");  
    for(
    $i=1$i<$num_results$i++)  
      {  
      
    $row=mysql_fetch_array($result); 
      
      echo
    "<table border=0 cellpadding=5 cellspacing=3 width=50% align=center>";
      echo
    "<tr>";
      echo
    "<td width=70% align=right>";
      echo 
    "No.".($page-1)*10+$i.".Name: ";   
      echo 
    htmlspecialcharsstripslashes($row["name"]));  
      echo
    "</td>";
      echo
    "<td valign=top rowspan=3 align=right>";
      echo
    "<img src=\"$row[images]\" width=180 height=160>";
      echo
    "</td>";
      echo
    "</tr>";
      echo
    "<tr>";
      echo
    "<td width=70% align=right>";  
      echo
    "Country: ";  
      echo 
    htmlspecialcharsstripslashes($row["country"])); 
      echo
    "</td>";
      echo
    "<tr>";  
      echo
    "<td width=70% align=right>";
      echo
    "Age:";
      echo 
    htmlspecialcharsstripslashes($row["age"]));
      echo
    "<td>";
      echo 
    "</tr>";
      
      echo
    "<table>";  
      }
    if(
    $page != 1)
    {
    print(
    "<a href=\"$PHP_SELF?page=" . ($page -1) . "\">Privious Page</a>");


    }
    print(
    "                          ");
    if(
    $page != 10){

    print(
    "<a href=\"$PHP_SELF?page=" . ($page 1) . "\">Next Page</a>");

    }

    echo (
    "<br>\n");
    }
    ?>

  • #2
    mat
    mat is offline
    Regular Coder
    Join Date
    Jul 2002
    Posts
    199
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well here is an example of a 'limit'. Limiting the amount of results that the SQL pulls out of the database to whatever number you specify, in this case 5 $page would be the current page number.


    PHP Code:
    $perPage 5;
    $offset = ($page-1)*$perPage;

    $sql "SELECT age, image, name
    FROM people
    WHERE age > 17 LIMIT $offset,$perPage"
    ;

    $result mysql_query($sql); 
    Last edited by mat; 12-03-2002 at 08:42 AM.

  • #3
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I fixed this script but not working. I need your help where is wrong.

    I have 14 database, so that it comes out 1page 4datas.

    I set 10 pages in this script. Is this working?

    10 pages equals to 100datas(10pages)but I have 14 datas in my database.

    Here is my script

    PHP Code:
    <?php 
    if(!isset($_POST['searchtype']) || !isset($_POST['searchterm']))  
    {   
    echo
    "you have not entered search details. Please go back and try again.";   
      exit;   

    else 

      
    $searchtype $_POST["searchtype"];  
      
    $searchterm $_POST["searchterm"];  
    }
      
    trim($searchterm); 

      
    $dbconnect mysql_connect("localhost""itohideo_hide""0810"); 
      if (!
    $dbconnect) { 
        echo( 
    "<p>Unable to connect to the " 
              
    "database server at this time.</p>" ); 
        exit(); 
      } 

      if (! 
    mysql_select_db("itohideo_japan") ) { 
        echo( 
    "<p>Unable to locate the host " 
              
    "database at this time.</p>" ); 
        exit(); 
      } 
       
       
       
       if(
    $searchterm==""){
       
       exit(
    "You should specify your request<a href=\"lookforgirl.html\">Go Back</a>");
       
       }
       
       else{
       
    $PHP_SELF $_SERVER["SCRIPT_NAME"];

    if (isset(
    $_GET["page"]))
    {
    $page $_GET["page"];
    }
    else {
    $page 1;
    }

    if(
    $page>10)
    {
    $page 10;

    }
       
    $perPage 10;
    $offset = ($page-1)*$perPage;
       
      
    $sql "SELECT * FROM girls WHERE " $searchtype " LIKE '%" $searchterm "%' limit $offset, $perPage";  
      
    $result mysql_query($sql);  
      
    $num_results mysql_num_rows($result);  
      print(
    $page."Page<br><br>\n");
      echo(
    "<p>itohideo.com found: " $num_results "</p>");  
    for(
    $i=0$i<$num_results$i++)  
      {  
      
    $row=mysql_fetch_array($result); 
      
      echo
    "<table border=0 cellpadding=5 cellspacing=3 width=50% align=center>";
      echo
    "<tr>";
      echo
    "<td width=70% align=right>";
      echo 
    "<strong>".($i+1).".Name: ";   
      echo 
    htmlspecialcharsstripslashes($row["name"]-1) * 10 $i );  
      echo
    "</td>";
      echo
    "<td valign=top rowspan=3 align=right>";
      echo
    "<img src=\"($row[images] -1)*10+$i\" width=180 height=160>";
      echo
    "</td>";
      echo
    "</tr>";
      echo
    "<tr>";
      echo
    "<td width=70% align=right>";  
      echo
    "Country: ";  
      echo 
    htmlspecialcharsstripslashes($row["country"]-1) * 10 $i ); 
      echo
    "</td>";
      echo
    "<tr>";  
      echo
    "<td width=70% align=right>";
      echo
    "Age:";
      echo 
    htmlspecialcharsstripslashes($row["age"]-1)*10+$i);
      echo
    "<td>";
      echo 
    "</tr>";
      
      echo
    "<table>";  
        
      }



    if(
    $page != 1)
    {
    print(
    "<a href=\"$PHP_SELF?page=" . ($page -1) . "\">Privious Page</a>");


    }
    print(
    "                          ");
    if(
    $page != 10){

    print(
    "<a href=\"$PHP_SELF?page=" . ($page 1) . "\">Next Page</a>");




    }



    ?>

  • #4
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Does anybody help me this script?

    Thanks a lot

  • #5
    New Coder
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You do of course need to specify the actual values in the limit clause, check out the documentation here


  •  

    Posting Permissions

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