Hi All !
Okay, i have a problem with the PHP Search String (strstr or strchar) and i was thinking to make a search for my personal webpage.
What i want exactly is to write a word to search for - > Look it up on web server database (PhPmyadmin) - > and retrieve results back to user's side.
Here is my basic code, maybe i'm doing it wrong..But i'm practicing !😕
function Check_Word($search){
require_once('database_conn.php');
$query = "select * from user_news";
$result = mysql_query($query);
if(!$result){
echo 'Could not add Image to database, try again later';
}
$num = mysql_num_rows($result);
echo "<font color=white size=4><center>Search Results</center></font><br />";
for($i=0; $i<$num; $i++){
$row = mysql_fetch_assoc($result);
if(strstr($row['zNews'],$search)){
echo "<table width=100% height=100% border=1 cellpadding=0 cellspacing=0 bordercolor=#b5e51d>";
echo "<tr><td><table width=100% height=100%>";
echo "<tr><td valign=top align=left bgcolor=#4e626b><font color=white size=2><b><ul><li><a href=view_more?zID=".$row['zID']." class=link>".$row['title']."</a></b></font></li></ul></td></tr></table></td></tr></table><br />";
do_html_footer();
exit;
}
elseif(!strstr($row['zNews'],$search)){
echo "<table width=100% height=100% border=0><tr><td><font color=orange size=2><center>Sorry,No Results Were Found</center></font></td></tr></table>";
return false;
do_html_footer();
exit;
}
}
}
mysql_close($link);
Well it worked, but not the result that i was expecting..It only searches the First Row ..If there is a value there, it will move to the Next Row..I Want to search all Row's at once the ($row['zNews']) part and outputs the result correctly. I think there is a problem with the looping????
Thank You Guys, i appreciate your time reading and helping.