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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Location
    India
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display 5 records per page

    Hi everybody,
    I am using PHP Expert Editor version 3.0.
    I want to fetch records from the database but I want to show 5 records per page.
    can anyone help.

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    do you have a current code that needs editing or do u need someone to code the whole script for you? check out some posts in here on how to retrieve info from databases and then go to the PHPFreaks Pagination tutorial located HERE

  • #3
    New to the CF scene
    Join Date
    May 2004
    Location
    India
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am accepting two values from user on that basis I am searching data from the database But it is showing the following error:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in searched_members.php

    members.htm file where I am accepting data from user :

    <form name="search" method="post" action="/searched_members.php">
    Search By
    <select name="options" size="1">
    <option value="">Select One</option>
    <option value="name">Name</option>
    <option value="address2">Locality</option>
    <option value="city">City</option>
    <option value="state">State</option>
    </select>
    Type the content to be searched
    <input type="text" name="search_element">
    <input type="submit" name="Submit" value="Go">
    </form>


    searched_members.php where code resideds to fetch the data from the database:

    <?php
    include("config.php");
    // navigation
    echo"<a href=\"members.php\" target=\"_self\">Member Search</a> > Search<br>";

    search_members($options, $search_element);

    function search_members($options, $search_element)
    {
    $result = "select * from members where $options like('%$search_element%') order by name, country, state, city, address2";
    limit_display($result);
    }
    function limit_display($result)
    {

    // limit value for number of records to be shown per page
    // query database to find total number of records to display

    $limit = 5;
    $query_count = $result;
    $result_count = mysql_query($query_count);
    $totalrows = mysql_num_rows($result_count);
    if(empty($page))
    $page = 1;
    $limitvalue = $page * $limit - ($limit);
    $query = $result . " LIMIT $limitvalue, $limit ";
    $result = mysql_query($query) or die("Error: " . mysql_error());
    $count_result = mysql_num_rows($result);

    // Display links at the top to indicate current page and number of pages displayed
    $numofpages = ceil($totalrows / $limit);
    if($totalrows==1)
    echo"<br>";
    $from=$limit*$page-$limit+1;
    $to=$from + $count_result-1;

    // start 123 next>> table
    echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
    <tr><td width=\"50%\" bgcolor=\"$bg_colour\" align=\"left\">";if($numofpages>1){echo"Showing: $from - $to</td><td width=\"50%\" bgcolor=\"$bg_colour\" align=\"right\"><b>Go to page:</b> ";}

    // display previous link if page is not 1
    if($page != 1){
    $pageprev = $page - 1;
    echo("<a href=\"$PHP_SELF?page=$pageprev\"><< PREV".$limit."</a>&nbsp;");
    }

    // display page nos if not 1
    for($i = 1; $i <= $numofpages; $i++){
    if($numofpages>1){
    if($i == $page)
    echo("&nbsp;".$i."&nbsp;");
    else
    echo("&nbsp;<a href=\"$PHP_SELF?page=$i&options=$options&search_element=$search_element\">$i</a>&nbsp;");
    }}

    // display next page link if there is more than one
    if(($totalrows - ($limit * $page)) > 0){
    $pagenext = $page + 1;
    echo("<a href=\"$PHP_SELF?page=$pagenext&options=$options&search_element=$search_element\">NEXT>></a>");
    }
    // end 123 next>> table
    echo"</td></tr></table><br>";

    // if there is a result display it
    if($totalrows!=0){
    print "<table border =1 width='100%' cellspacing='0' cellpadding='0'>\n";
    while ($a_row = mysql_fetch_object($result))
    {
    print "<tr>\n";
    print "<td>";
    print"<br>";
    print "\t Name : $a_row->name<br>\n Address : $a_row->address1 <br> Locality :$a_row->address2<br> City : $a_row->city $a_row->pin<br> State : $a_row->state<br>";
    if ($a_row->res_phone !="")
    print "Ph.(Res) : $a_row->res_phone ";
    if ($a_row->off_phone !="")
    print " Ph.(Off) : $a_row->res_phone ";
    if ($a_row->mobile_phone !="")
    print " Mobile : $a_row->res_phone";
    print "</td>";
    print "</tr>\n";
    }
    print"</table>\n";

    // Display links at the bottom to indicate current page and number of pages displayed
    echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
    <tr><td bgcolor=\"$bg_colour\" align=\"right\">";

    if($numofpages>1){echo"<b>Go to page:</b> ";}

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

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

    if(($totalrows - ($limit * $page)) > 0){
    $pagenext = $page + 1;
    echo("<a href=\"$PHP_SELF?page=$pagenext&options=$options&search_element=$search_element\">NEXT >></a>");
    }else
    echo"<br><br></tr></td></table>";
    }
    }
    ?>

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    could it be where you have
    Code:
    order by name, country, state, city, address2
    shouldnt you only have one ORDER BY statement and a DESC or ASC afterwards?

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can have more than one order by, but it should be in in the form:

    ORDER BY col1 DESC, col2 DESC, col3 ASC ect.

  • #6
    New to the CF scene
    Join Date
    May 2004
    Location
    India
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "select * from members where $options like '%$search_element%' order by name, country, state, city, address2";

    This order by clause is running in MySQL-Front ver. 2.5 independently. But when I run it from PHP file it is displaying following error :

    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%%' order by name, country, state, city, address2'


  •  

    Posting Permissions

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