![]() |
| ||||||||||
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| PHP The most widely used server-side programming language for web applications. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| |||
| 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:  '.$row['Discription']; echo '<br/> ItemNumber:  '.$row['ItemNumber']; echo '<br/> Price: $ '.$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" |
| |||
| 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:  '.$description; echo '<br/> ItemNumber:  '.$itemNumber; echo '<br/> Price: $ '.$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. |
![]() |
| Thread Tools | |
| Display Modes | |
| |