fert Posted October 27, 2006 Share Posted October 27, 2006 this code is a search code that has the names of webpages in a database, opens them, reads them and looks for the search phrase in each, but it doesn't work can anybody tell me why?[code]<html><head><title>Search</title></head><body bgcolor="#999900"><h1>Search results</h1><?php $cn=@mysql_query("host","username","password") or die(mysql_error()); @mysql_select_db("db_name",$cn) or die(mysql_error()); $name="page"; $files; $result=@mysql_query("SELECT * FROM search_pages",$cn) or die(mysql_error()); $num=mysql_num_fields($result); while($row=mysql_fetch_array($result)); for($count=1;$count<$num;$count++) { $name.=$count; $file=@fopen($row[$name],"r") or die("Cannot open file"); $text=@fread($file,filesize($row[$name])) or die("Cannot read file"); if(stristr($text,$_POST[search])) { $files[$count]=$row[$name]; } else { $files[$count]=""; } @fclose($file); $name="page"; } for($count=1;$count<$num;$count++) { if($files[$count]!="") { echo "<p><a href=\"http://www.mysite.net".$files[$count]."\">{$count}</a></p>"; } }?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
btherl Posted October 27, 2006 Share Posted October 27, 2006 The database connection should be[code]$cn=@mysql_connect("host","username","password") or die(mysql_error());[/code]where host, username and password are replaced with the appropriate values for your database.Regarding fetching the data, are you expecting to get several rows of data, or just a single row with many fields? Your code looks like it expects a single row with many fields. Quote Link to comment Share on other sites More sharing options...
fert Posted October 27, 2006 Author Share Posted October 27, 2006 [quote author=btherl link=topic=112894.msg458421#msg458421 date=1161922379]The database connection should be[code]$cn=@mysql_connect("host","username","password") or die(mysql_error());[/code][/quote]Thanks now it works Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.