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 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    41
    Thanks
    3
    Thanked 0 Times in 0 Posts

    db results paging

    Ok i realy need to know why my search is not working correctly lol.....well it works it brings results but does not display pages..

    the limit is 5 so it displays only 5 results...(i dont have much in db but i have more then 5 items)

    Ok heres the code:

    PHP Code:

    <?php
    $searchin 
    $_GET[searchlink];

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

    $max_results 5
    $from = (($page $max_results) - $max_results);  

    include(
    'dbconfig.php');

    $query="SELECT linkname, linkdes, 
    url FROM indexedlinks WHERE linkname LIKE  '%$searchin%' LIMIT $from, $max_results"


    $result=mysql_query($query); //already tryed .mysql_error() on all

    while($srows=mysql_fetch_array($result)) {

    $name $srows[linkname];
    $linkdisc $srows[linkdes];
    $url $srows[linkurl];


    echo 
    "<table width=\"100%\" bgcolor=\"#ffffff\" cellspacing=\"2\" cellpadding=\"2\" border=\"1\">
          <tr>"
    ;

    echo 
    "<td align=\"left\"><font color=\"#202020\" size=\"2\"> Site Name:</font></td>
          <td align=\"left\"> "
    ;

    echo 
    $sitename;
               
    echo 
    "</td></tr><tr>";

    echo 
    "<td align=\"left\"><font color=\"#202020\" size=\"2\"> Site Discription:</font></td>
          <td align=\"left\"> "
    ;

    echo 
    $linkdisc;
               
    echo 
    "</td></tr><tr>";

    echo 
    "<td align=\"left\"><font color=\"#202020\" size=\"2\"> Url:</font></td><td align=\"left\"> ";

    echo 
    "<a href=\"$url\" target=_blank\">$url</a>";
               
    echo 
    "</td></tr>";

    echo 
    "</table> <br><br>";
    }

    $total_results ="SELECT COUNT(*) as Num FROM thelinks"

    $reso=mysql_query($total_results) or die(mysql_error());

    $total_pages ceil($total_results $max_results); 

    echo 
    "<center>Select a Page<br>"

    if(
    $page 1){ 
        
    $prev = ($page 1); 
        echo 
    "<a href=\"?page=$prev\"><<Previous</a> "


    for(
    $i 1$i <= $total_pages$i++){ 
        if((
    $page) == $i){ 
            echo 
    "$i "
            } else { 
                echo 
    "<a href=\"?page=$i\">$i</a> "
        } 


    if(
    $page $total_pages){ 
        
    $next = ($page 1); 
        echo 
    "<a href=\"?page=$next\">Next>></a>"

    echo 
    "</center>"
    ?>

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    UK
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm guessing that it's having problems with this:

    PHP Code:
    $total_pages ceil($total_results $max_results); 
    You're trying to divide a string by a number. $total_results is your SQL string.

  • #3
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,083
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Put some echo statements in strategic places in your code, so that you can see what the values are for your variables at each step of the way. When your expected and actual values differ, then you have pinpointed a problem with your code.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!


  •  

    Posting Permissions

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