Left Quote    I think there is a world market for maybe five computers.
- Thomas Watson, Chairman of IBM 1943    
Right Quote
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply

        Viewing Topic: problem to show next page-any idea?
  This user is offline  firers3
  Subject: "problem to show next page-any idea?" Posted: @ 7:51 pm on Jul 15 2008   
Member #: 714
Rank: User - (11)
Since: 07/04/08
Posts: 11

I developed a keyword search page to display results with page navigation. the problem is I can only show the first 10 search results on first page. then when i click "Next 10" to link next page, it just sticks at the first page and not going anywhere. Anyone can give me a hand? Thanks. Code is here.This is the form:[code}< form name="form " action="Te stresult.php&qu ot; method="ge t">
<input type="text " name="q&qu ot; />
<input type="subm it" name="Subm it" value="Sea rch" />

Here is the code for the search :


// Get the search variable from URL

$var = @$_GET['q'] ;
$trimmed = trim($var); //trim whitespace from the stored variable

// rows to return

// check for an empty string and display a message.
if ($trimmed == "") {
echo "<p> Please enter a search...</p >";

// check for a search parameter
if (!isset($var))< br /> {
echo "<p> We dont seem to have a search parameter!</ p>";

$hostname = "localhost "; // Our DB server.
$username = "xx"; // The username you created for this database.
$password = "xx"; // The password you created for the username.
$usertable = "xx"; // The name of the table you made.
$dbName = "xx"; // This is the name of the database you made.

MYSQL_CONNECT($ hostname, $username, $password) OR DIE("DB connection unavailable&quo t;);
mysql_select_db ( "$dbName&q uot;) or die( "Unable to select database") ;

// Build SQL Query
$query = "select * from table where username like \"%$trimme d%\"
order by username"; // EDIT HERE and specify your table and field names for the SQL query

$numresults=my sql_query($quer y);
$numrows=mysql _num_rows($numr esults);

// If we have no results, offer a google search as an alternative

if ($numrows == 0)
echo "<h4> ;Results</h4 >";
echo "<p> Sorry, your search: &quot;" ; . $trimmed . "&quot ; returned zero results</p&g t;";

// google
echo "<p> <a href=\"htt p:// com/search?q=&q uot;
. $trimmed . "\" target=\"_ blank\" title=\"Lo ok up
" . $trimmed . " on Google\"&g t;Click here</a> to try the
search on google</p> ;";

// next determine if s has been passed to script, if not use 0
if (empty($s)) {

// get results
$query .= " limit $s,$limit" ;
$result = mysql_query($qu ery) or die("Could n't execute query");
// display what the person searched for
echo "<p> You searched for: &quot;" ; . $var . "&quot ;</p>&quo t;;

// begin to show results set
echo "Results&q uot;;
$count = 1 + $s ;

// now you can display the results returned
while ($row= mysql_fetch_arr ay($result)) {
$title = $row["user name"];

echo "$count.)& amp;nbsp;$title " ;
$count++ ;

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

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

// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$lim it);
print "&nbsp ;<a href=\"$PH P_SELF?s=$prevs &q=$var\&qu ot;>&lt; &lt;
Prev 10</a>&am p;nbsp&nbsp ;";

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

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

if ($numrows%$limi t) {
// has remainder so add one page

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

// not last page so give NEXT link
$news=$s+$limit ;

echo "&nbsp ;<a href=\"$PH P_SELF?s=$news& amp;q=$var\&quo t;>Next 10 &gt;&gt ;</a>&quo t;;

$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p> Showing results $b to $a of $numrows</p& gt;";


    Viewed: 4,452 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: problem to show next page-any i..." Posted: @ 1:54 pm on Jul 16 2008    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

this part is your problem:


// next determine if s has been passed to script, if not use 0
if (empty($s)) {

that assumes register_global s is on, and it sounds like it's off for you and should stay off. i recommend adding this code before that part:

if(is_numeric( $_GET['s']))< br /> $s = $_GET['s'];

i suspect the $PHP_SELF isn

please note that the above post is likely made up in its entirety.

    Viewed: 4,444 Times | Reply to This | To top
  This user is offline  firers3
  Subject: "re: problem to show next page-any i..." Posted: @ 4:13 pm on Jul 16 2008    
Member #: 714
Rank: User - (11)
Since: 07/04/08
Posts: 11

Thank you very much. It works great. now I guess if some one need the code, they can directly get from here and it has been tested.

    Viewed: 4,440 Times | Reply to This | To top
Viewing Page: 1 of 1

1 |

You must be logged in to post on the forums. Login or Register

"" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank