473,564 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search page's result

51 New Member
HI All
I have a search page' s result which view 3results/per page,but my "next" link to view next page is not working.
Here is my code :


[PHP]<?php
// Get the search variable from URL
$string = @$_GET['q'] ;
$trimmed = trim($string); //trim whitespace from the stored variable
// rows to return
$limit=3;
// check for an empty string and display a message.
if ($trimmed == "")
{
echo "";
exit;
}
// check for a search parameter
if (!isset($string ))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
//connect to your database
mysql_connect(" localhost","pur pasia_CMS","CMS "); //(host, username, password)

//specify database
mysql_select_db ("purpasia_VFM" ) or die("Unable to select database"); //select which database we're using

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

$numresults=mys ql_query($query );
$numrows=mysql_ num_rows($numre sults);

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

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

// google
echo "<p><a href=\"http://www.google.com/search?q="
. $trimmed . "\" target=\"_blank \" title=\"Look up
" . $trimmed . " on Google\">Click here</a> to try the
search on google</p>";
}else

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

// get results
$query .= " limit $s,$limit";
$result = mysql_query($qu ery) or die("Couldn't execute query");

// display what the person searched for
//echo "<p>You searched for: &quot;" . $var . "&quot;</p>";

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

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

echo "$count.)&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-$limit);
print "&nbsp;<a href=\"$PHP_SEL F?s=$prevs&q=$s tring\">&lt;&lt ;
Prev</a>&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
$pages++;
}

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

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

echo "&nbsp;<a href=\"$PHP_SEL F?s=$news&q=$st ring\">Next&gt; &gt;</a>";
}

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

?>[/PHP]

Any idea why is this problem?
Here is the output : http://www.purpleasia.com/clients/VF....php?s=1&q=vfm
thanks so much
Apr 28 '08 #1
5 2617
Markus
6,050 Recognized Expert Expert
You do realise the difference between php and html? Use the correct code tags.

[php]
<?php
// Get the search variable from URL
$string = @$_GET['q'] ;
$trimmed = trim($string); //trim whitespace from the stored variable
// rows to return
$limit=3;
// check for an empty string and display a message.
if ($trimmed == "")
{
echo "";
exit;
}
// check for a search parameter
if (!isset($string ))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
//connect to your database
mysql_connect(" localhost","pur pasia_CMS","CMS "); //(host, username, password)

//specify database
mysql_select_db ("purpasia_VFM" ) or die("Unable to select database"); //select which database we're using

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

$numresults=mys ql_query($query );
$numrows=mysql_ num_rows($numre sults);

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

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

// google
echo "<p><a href=\"http://www.google.com/search?q="
. $trimmed . "\" target=\"_blank \" title=\"Look up
" . $trimmed . " on Google\">Click here</a> to try the
search on google</p>";
}else

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

// get results
$query .= " limit $s,$limit";
$result = mysql_query($qu ery) or die("Couldn't execute query");

// display what the person searched for
//echo "<p>You searched for: &quot;" . $var . "&quot;</p>";

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

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

echo "$count.)&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-$limit);
print "&nbsp;<a href=\"$PHP_SEL F?s=$prevs&q=$s tring\">&lt;&lt ;
Prev</a>&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
$pages++;
}

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

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

echo "&nbsp;<a href=\"$PHP_SEL F?s=$news&q=$st ring\">Next&gt; &gt;</a>";
}

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

?>
[/php]
Apr 28 '08 #2
rpnew
188 New Member
Hi,
It seems that you are not setting the variable 'S' while reloading the page.
You need to do something like this.
[PHP]
if(isset($_GET['s']))
{
$s=$_GET['s'];
}
$string = @$_GET['q'] ;
$trimmed = trim($string);
[/PHP]

So even if you are clicking NEXT you are still with s=0.
Let me know if i'm wrong or if it helps...

Regards,
RP
Apr 29 '08 #3
th1982
51 New Member
Thanks rpnew
Now it s working
Pls help me next time if i have question
Thanks again
Best regards!!
Apr 30 '08 #4
rpnew
188 New Member
Thanks rpnew
Now it s working
Pls help me next time if i have question
Thanks again
Best regards!!
Hi,
Glad that you got it working.
Post back to forum whenever you've any problem or questions...

Regards,
RP
Apr 30 '08 #5
anjar666
1 New Member
although this thread has been long but this is very helpful thank you...
Aug 20 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

83
5866
by: D. Dante Lorenso | last post by:
Trying to use the 'search' in the docs section of PostgreSQL.org is extremely SLOW. Considering this is a website for a database and databases are supposed to be good for indexing content, I'd expect a much faster performance. I submitted my search over two minutes ago. I just finished this email to the list. The results have still not...
1
2210
by: abhijan | last post by:
We have come across a typical problem with Site Search Pro Gold 2.0 - Any text/word/searchkey having apostrophe mark are not getting indexed by the system as the search result is not displaying any of them. For example: If we have a paragraph in a page A as "I have a big brother named Apurba. Apurba's attitude towards work is very nice....
6
2629
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect the fields chosen. The first page, where they select the search fields and submit: <?php $db = mysql_connect("localhost", "root",...
3
1930
by: fjm | last post by:
Hello all, I have 2 files. index.php which is a log in page and a search page. After the user logs in they are taken to the search page by way of a checklogin script that verifies the user. My index page has two fields: customer password Here are the contents of both of my files. I'm sure I am missing something here but 4 hours...
10
2264
by: jonathan184 | last post by:
Hi I tried getting this to work through dreamweaver but it did not. So i found a n example on the internet , i followed everything exactly the search script does not work. Could somebody help me this please. Thanks for your help in advance. The form and script are on the same page. <?php require_once('../Connections/rs_ais.php'); ?> ...
4
3513
by: bendlam | last post by:
I have a page that contains search criteria and when you click on the search button it causes a post back that populates a dataview on the same page. One of the gridview columns contains a link that navigates to a details page. When I try to go back to the search results page i get "Page cannot be displayed" error. How do i go back to the...
13
2104
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any suggestions will be greatly appreciated. Jim #! /usr/bin/perl -w use strict;
3
1479
by: Bigalan | last post by:
Hello, i am relatively new to PHP and i am struggling with printing multiple search results on to different pages. The code below works ok but when you click on next page button, it brings up a blank screen. I think it might have something to do with resetting the $found variable. Can you have a quick look? any suggestions would be greatly...
5
1866
by: silmana | last post by:
Hi i have this script that i want to use as php or html but i cant find the problem, could anyone solve the problem, i dont know why i cannot use it in php or html file // OBS! Några saker måste justeras för att skriptet skall fungera // 1) Du måste ange antal webbsidor som skall genomsökas // 2) Du måste lista dessa webbsidor // 3) Du...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.