andylai Posted March 5, 2007 Share Posted March 5, 2007 I try to create a search function for mysql database on the web page but it didn't works. Can anyone help? Thanks. Andy <?php include ("db.php"); $path="file:\\\fileserver\WDrawing"; $path1="file:\\\fileserver\ADrawing"; ?> <html> <body> <h1 align="center"> Drawing File list </h1> <hr> <?php echo $search; ?> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="GET"> Search: <input type="text" name="search"> <input type="submit" value="GO"> <hr> </form> </div> <BR> <?php if (isset($action)){ $result = mysql_query_ec("SELECT filename,code FROM filelist where filename like %$search%"); while ($filename = mysql_fetch_assoc($result)) { $filename = $row["filename"]; $code = $row["code"]; If ($code == "w") { $fn=$path."\\".substr($filename,0,1)."\\".$filename; echo "<a href='$fn'>$filename</a><br>"; } else { $fn=$path1."\\".$filename; echo "<a href='$fn'>$filename</a><br>"; } } header ("location:index1.php"); exit; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/41322-need-help-on-search-function/ Share on other sites More sharing options...
chronister Posted March 5, 2007 Share Posted March 5, 2007 What exactly is it not doing ? Is it doing anything? A little more information would be helpful. Link to comment https://forums.phpfreaks.com/topic/41322-need-help-on-search-function/#findComment-200210 Share on other sites More sharing options...
andylai Posted March 5, 2007 Author Share Posted March 5, 2007 When I type a word in search and submit it, nothing reply on the result. I have another page that will display all file and that works. Thanks Andy I try to create a search function for mysql database on the web page but it didn't works. Can anyone help? Thanks. Andy <?php include ("db.php"); $path="file:\\\fileserver\WDrawing"; $path1="file:\\\fileserver\ADrawing"; ?> <html> <body> <h1 align="center"> Drawing File list </h1> <hr> <?php echo $search; ?> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="GET"> Search: <input type="text" name="search"> <input type="submit" value="GO"> <hr> </form> </div> <BR> <?php if (isset($action)){ $result = mysql_query_ec("SELECT filename,code FROM filelist where filename like %$search%"); while ($filename = mysql_fetch_assoc($result)) { $filename = $row["filename"]; $code = $row["code"]; If ($code == "w") { $fn=$path."\\".substr($filename,0,1)."\\".$filename; echo "<a href='$fn'>$filename</a><br>"; } else { $fn=$path1."\\".$filename; echo "<a href='$fn'>$filename</a><br>"; } } header ("location:index1.php"); exit; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/41322-need-help-on-search-function/#findComment-200275 Share on other sites More sharing options...
chronister Posted March 5, 2007 Share Posted March 5, 2007 $result = mysql_query_ec("SELECT filename,code FROM filelist where filename like %$search%"); where are you defining $search? and what is mysql_query_ec ? A google search returned nothing on this statement. Try doing this $query="SELECT filename,code FROM filelist where filename like %$search%"; $result = mysql_query($query); echo $query; take a look at the echo'd query and see if it is populating the $search var. Link to comment https://forums.phpfreaks.com/topic/41322-need-help-on-search-function/#findComment-200287 Share on other sites More sharing options...
Archadian Posted March 5, 2007 Share Posted March 5, 2007 i think this: if (isset($action)){ needs to be this: if (isset($_GET['search'])){ Link to comment https://forums.phpfreaks.com/topic/41322-need-help-on-search-function/#findComment-200368 Share on other sites More sharing options...
Barand Posted March 6, 2007 Share Posted March 6, 2007 You will need single quotes around %$search% $query="SELECT filename,code FROM filelist where filename like '%$search%' "; Link to comment https://forums.phpfreaks.com/topic/41322-need-help-on-search-function/#findComment-200394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.