473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Hey guys! Can you help? PHP search results

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 appreciated.



<?
if ($_GET) $vars=$_GET;
else $vars=$_POST;

$found = $vars['search'];


if (!($limit)){
$limit = 10;} // Default results per-page.

if (!($page)){
$page = 0;} // Default page value.


if ($found == "")
{
echo "<p>You forgot to enter a search term<br>";

exit;
}

$username="****";
$password="******";
$database="******";
$host="*****************";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

//convert to uppercase to allow for case sensisivities
$found = strtoupper($found);
//strip code from search term
$found = strip_tags($found);
//strip spaces from search term
$found = trim ($found);

$check = mysql_query("SELECT * FROM song WHERE upper(description) LIKE '%$found%'");

$anymatches=mysql_num_rows($check);
if ($anymatches == 0)
{
echo "Sorry, no matching results were found<br><br><br>";
}



$pages = intval($anymatches/$limit); // Number of results pages.

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

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

$current = ($page/$limit) + 1; // Current page number.

if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.

else {
$total = $pages;} // Else total pages is $pages value.

$first = $page + 1; // The first result.

if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.

else{
$last = $anymatches;} // If last results page, last result equals total number of results

echo "Results <b>$first</b> - <b>$last</b> of <b>$anymatches</b><br><br>";


$search = mysql_query("SELECT * FROM song WHERE upper(description) LIKE '%$found%' LIMIT $page, $limit");





while($result = mysql_fetch_array($search))
{
PRINT RESULTS!!!
}



if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$found&page=$back_page&limi t=$limit\">back</a> \n");}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b> \n");} // If current page don't give link, just text.
else{
echo("<a href=\"$PHP_SELFquery=$found&page=$ppage&limit=$li mit\"> $i</a> \n");}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"$PHP_SELF?query=$found&page=$next_page&limi t=$limit\">next</a>\n");}




?>

Thanks!
Bigalan
Feb 5 '08 #1
3 1473
MarkoKlacar
296 Expert 100+
Hi,

Could you re-post using code tags?
Thanks
Feb 5 '08 #2
Hi,
thanks for your response,
Do you mean the html tags?
alan
Feb 5 '08 #3
MarkoKlacar
296 Expert 100+
Hi,
thanks for your response,
Do you mean the html tags?
alan
Hi,

I mean php-code tags, easier to see the code and comment that way...

Thanks..
Feb 6 '08 #4

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

Similar topics

6
by: echo01 | last post by:
Hey when do you guys think 5.0 will be stable or considered stable. i think the are up to 5.0.2?
2
by: sheldon279 | last post by:
Hi guys. First time poster long time reader. Just wanted to say "Hi" ;) On a side note my Hubby is REAL excited about this new IPO stock GRDX. They just started trading this one like 2 days...
354
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets...
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
10
by: Tom Dauria | last post by:
My situation is that I am developing and supporting databases for my company. I have been using paper folders one for each project both new and support. And support means I am still developing...
92
by: Jeffrey P via AccessMonster.com | last post by:
Our IT guys are on a vendetta against MS Access (and Lotus Notes but they've won that fight). What I can't understand is, what's the problem? Why does IT hate MS Access so much. I have tried...
17
by: ahaupt | last post by:
Hi all, I'm currently writing a load of class libraries, but not the main application iteslf. I want to provide some method for reporting errors back to the main application. At the moment...
3
by: Ruslan Shlain | last post by:
Hello everyone, I have a question and I hope someone could answer it for me. I have a APSX page that is a container and when needed it loads one of many user controls. One of my user controls that...
5
by: Jim Bancroft | last post by:
Inexplicably one of my aspx pages is ignoring the Page_Load handler. The page worked fine this morning, but then I added a couple of "using" directives and uncommented a method call about halfway...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.