LiveZilla Live Help
 


Go Back   Chime Host - Web Hosting Forum > World Wide Web > Programming / Scripting / Coding Forum > PHP
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

PHP The most widely used server-side programming language for web applications.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-20-2009, 12:27 PM
Junior Member
 
Join Date: Oct 2009
Kelly H is on a distinguished road
Default PHP Search result help?

Here is the code i have


<?php
mysql_connect ("localhost", "***********","**********") or die (mysql_error());
mysql_select_db ("kelly");

$term = $_POST['term'];

$sql = mysql_query("select * from text where Color like '%$term%' or ItemNumber like '%$term%' or Discription like '%$term%'or Price like '%$term%' or Information like '%$term%' ");


while ($row = mysql_fetch_array($sql)){
echo ''.$row['URL'];
echo '<br/> Discription:&nbsp '.$row['Discription'];
echo '<br/> ItemNumber:&nbsp '.$row['ItemNumber'];
echo '<br/> Price:&nbsp$ '.$row['Price'];
echo '<br/><br/>';
}

?>



Here is what i need it to do.
Say you do a search for oreo cookie this is going to search my DB well the only problem is that i dont have any thing close to oreo cookie in there. Right now if i were to do a search for it it would just give me a blank result. What code would i need to add to my code to have it say " The search you just made did not find any thing Please try again"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-20-2009, 02:16 PM
Junior Member
 
Join Date: Feb 2007
eric is on a distinguished road
Default

if(mysql_num_rows($sql) == 0)
echo("The search you just made did not find any thing Please try again");
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-20-2009, 02:16 PM
Junior Member
 
Join Date: Mar 2008
chris b is on a distinguished road
Default

Try this:
<?php
mysql_connect ("localhost", "***********","**********") or die (mysql_error());
mysql_select_db ("kelly");
$term = $_POST['term'];
$sql = mysql_query("select * from text where Color like '%$term%' or ItemNumber like '%$term%' or Discription like '%$term%'or Price like '%$term%' or Information like '%$term%' ");
if(!mysql_fetch_array($sql)){
echo "Your search did not match with anything. Please try again";
}else{
while(list($url,$description,$itemNumber,$price)=m ysql_fetch_array($sql)){
echo ''.$url;
echo '<br/> Discription:&nbsp '.$description;
echo '<br/> ItemNumber:&nbsp '.$itemNumber;
echo '<br/> Price:&nbsp$ '.$price;
echo '<br/><br/>';
}
}
?>
I cannot guarantee if your code is correct.
If it doesn't Create another query, except where it says "SELECT * FROM", do "SELECT COUNT(*) FROM".
$sql = SELECT COUNT(*) FROM...
$result = mysql_fetch_array($sql);
$result = $result[0];
if($result != 0){ ... display results... }else{...no matches...}
Good Luck!
If you need further assistance/advice, feel free to contact me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 07:03 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ChimeHost, a Profuse Solutions LLC company