CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Jan 2009
    Posts
    1

    Exclamation PHP MySQL problem

    Hello guys,
    I am having a search script which suppose to take results out of my mysql
    database and display on a page 10 results each
    if the results are more then 10 it should create another page
    or pages with Next >> and Prev << link so anyone can move
    forward and backward on those results page.

    This script do everything fine counting total records display's 1 to 10
    records on first page but at second location on same page i want it to daisplay
    Showing results 1 to 10 of total records found it show 5 to 14, ant it
    displays a link to Next which is not working.

    Here is the code to generate pages please have a look and let me
    know where I am wrong.

    PHP Code:
    // begin to show results set
    echo " found  $numrows results <p>";
    $count $s;

    // now you can display the results returned
      
    while ($rowmysql_fetch_array($result)) {

      
    $title $row["sname"];
      
    $url $row["url"];
      
    $message $row["massage"];
    //&nbsp;<a href=\"$row['url']\">"$row['sname']</a><br /> 
    $row['massage']<br><hr>'\

      echo "$count.)&nbsp";
      echo "<b><a href=\"$url\" target=\"_blank\">$title</a></b>";
      echo "<br>";
      echo "$message<br><hr height=12 color=lightblue><br>";
      $count++;

      }

    $currPage = (($s/$limit) + 1);

    //break before paging
      echo "<br />";

      // next we need to do the links to other results &lt;&lt;
      if ($s>=1) { // bypass PREV link if s is 0
      $prevs=($s-$limit);
      print "&nbsp;<a href='
    {$_SERVER['PHP_SELF']}?s=$prevs&q=$var'> <<<
      Prev 10</a>&nbsp&nbsp;";
      }

    // calculate number of pages needing links
    //  $s=intval($numrows/$limit);
      $s=ceil($numrows/$limit);


    // $s now contains int of pages needed unless there is a remainder from 
    division

      if ($numrows%$limit) {
      // has remainder so add one page
      $s++;
      }

    // check to see if last page
      if (!((($s+$limit)/$limit)==$s) && $s!=1) {

      // not last page so give NEXT link  $PHP_SELF &gt;&gt;
      $news="$s+$limit";

      echo "&nbsp;<a href='
    {$_SERVER['PHP_SELF']}?s=$news&q=$var'>Next 10 >>> 
    </a>";

      }

    $a = $s+$limit;
      if ($a > $numrows) { $a = $numrows; }
    $b = $s+1;
      echo "<p>Showing results $b to $a of $numrows</p>";
    include ('
    footer.inc');
    ?> 
    Thank You
    Last edited by PeejAvery; January 26th, 2009 at 06:55 PM. Reason: Added PHP tags.

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured