baby83 Posted July 24, 2008 Share Posted July 24, 2008 i have this html code... to search a data. <form name="form1" method="post" action="search.php"> <p align="center"> <input type="text" name="search"> <input type="submit" name="Submit" value="Search"> <input type="reset" name="Reset" value="Reset"> </p> <p align="center"> </p> </form> and this is my sql code... $search = $_POST['search']; $query = mysql_query("SELECT a, b FROM $usertable WHERE ic LIKE '$search' ORDER BY ic"); while ($row = mysql_fetch_array($query)) { $a_id = $row['a_id']; $ic=$row['ic']; $a = $row['a']; $b=$row['b']; echo "<center>"; echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>"; echo " <tr>"; echo "<td colspan='2'>"; print ("Info: "); echo "$ic"; echo "</td>"; echo "<td>"; echo "$a"; echo "</td>"; echo "<td>"; echo "$b"; echo "</td>"; echo "</tr>"; i get this result: Info: mark susan Info: mark anita 'mark' is in field 'a' and 'susan and anita' is in field b. the problem is, when i search the ic, it shows both infos. yes, in my table, it contains: example: a_id a b ic 1 mark susan 1011 2 mark anita 1011 i want the result shows like this: info: mark susan anita can anybody help me? Link to comment https://forums.phpfreaks.com/topic/116357-how-to-search-data/ Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 try changing this line... $query = mysql_query("SELECT a, b FROM $usertable WHERE ic LIKE '$search' ORDER BY ic"); to this: $query = mysql_query("SELECT a, b FROM $usertable WHERE ic LIKE '$search' ORDER BY ic") or die("Problem in query!"); and let us know if you get any errors. Link to comment https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598287 Share on other sites More sharing options...
baby83 Posted July 24, 2008 Author Share Posted July 24, 2008 ive got this result... Info: mark susan [back] Info: mark anita [back] No data found... sorry Link to comment https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598288 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 Try... <?php $search = $_POST['search']; $query = mysql_query("SELECT a, b FROM $usertable WHERE ic LIKE '$search' ORDER BY ic"); if(mysql_num_rows($query) < 1) { die("There was no results found!"); } $row = mysql_fetch_array($query); $a_id = $row['a_id']; $ic=$row['ic']; $a = $row['a']; $b=$row['b']; echo "<center>"; echo "<table width='400' border='0' cellspacing='0' cellpadding='0'>"; echo " <tr>"; echo "<td colspan='2'>"; print ("Info: "); echo "$ic"; echo "</td>"; echo "<td>"; echo "$a"; echo "</td>"; echo "<td>"; echo "$b"; echo "</td>"; echo "</tr>"; ?> Link to comment https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598292 Share on other sites More sharing options...
baby83 Posted July 24, 2008 Author Share Posted July 24, 2008 ok... then ive got this result... Info: mark susan but how about the info about.... mark and anita? because in my table... i have: id a b ic 1 mark susan 1011 2 mark anita 1011 so if i search '1011', it will shows: Info: mark susan anita can u help me? Link to comment https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598296 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 Whats your question exactly? You've kinda lost me. The script appears to be searching fine. But isn't giving you the correct data? sounds like its a problem with the query itself. Please, correct me if I'm wrong. Link to comment https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598298 Share on other sites More sharing options...
baby83 Posted July 24, 2008 Author Share Posted July 24, 2008 ok.... actually i want to show the result like this: Info: mark susan anita it means: mark has 2 daug name susan and anita. i separate it because both susan and anita have their own details. example: in my table: id a b ic age 1 mark susan 1011 20 2 mark anita 1011 15 yes i agree your given code is correct. but it doesnt show all the daug that mark has... hmmm... Link to comment https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598308 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 Try removing the LIKE clause altogether and make the query like this... $query = mysql_query("SELECT a, b FROM $usertable WHERE ic = '$search' ORDER BY ic"); Link to comment https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598311 Share on other sites More sharing options...
baby83 Posted July 24, 2008 Author Share Posted July 24, 2008 i havent put any LIKE clause... Link to comment https://forums.phpfreaks.com/topic/116357-how-to-search-data/#findComment-598313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.