yousuf hussain wrote: > > > Dear members: > > I came across a problem that while searching a record from a database it > only returns one field record. i want to search it with different option. > Code is given below > Only Unit record is returned > > <?php > include "header.php"; > ?> > <td height="100%" valign="top"> > <form action="SearchResult.php" method="post"> > <table align="center" border="0" cellpadding="0" cellspacing="0" > width="100%"> > <tr> > <td align="center" bgcolor="#EBEADB" height="18" > class="normaltext">Search Record</td> > </tr> > <tr> > <td align="center"> > <table align="center" border="0" cellpadding="5" cellspacing="0" > height="100"> > <tr class="normaltext"> > <td align="center">Search by:</td> > <td align="center"> > <select name="search"> > <option selected>Select</option> > <option value="syard">SYard</option> > <option value="price">Price</option> > <option value="unit">Unit</option> > </select> > </td> > <td align="center"><input type="text" name="search"></td> > <td ><input type="submit" name="btSearch" value="Search"></td> > </tr> > </table> > </td> > </tr> > </table> > </form> > </td> > > </tr> > </table> > </body> > </html> > .................................................................................................................... > > > <?php > $searchText = $_REQUEST["search"]; > include "header.php"; > ?> > <td valign="top"> > <table width="100%" cellpadding="0" cellspacing="0" border="0" > align="center"> > <tr> > <td colspan="8" height="30" align="center" class="normaltext2">Search > Result</td> > </tr> > <tr bgcolor="#CCCCCC" height="22"> > <td ><strong>No</strong></td> > <td ><strong>SYard</strong></td> > <td ><strong>Street</strong></td> > <td><strong>Phase</strong></td> > <td><strong>Unit</strong></td> > <td><strong>Catagory</strong></td> > <td><strong>Price</strong></td> > <td><strong>Comments</strong></td> > </tr> > <?php > include "connection.php"; > if($searchText=="syard"){ > $mySQL = "select * from addbunglow where syard='$searchText' and > isactive=1 order by bangid"; > echo "syard:".$searchText; > } > else if($searchText=="price"){ > $mySQL = "select * from addbunglow where price='$searchText' and > isactive=1 order by bangid"; > echo "price:".$searchText; > } > else { > $mySQL = "select * from addbunglow where unit='$searchText' and > isactive=1 order by bangid"; > echo "unit:".$searchText; > } > $result = mysql_query($mySQL); > $counter = 1; > while($row = mysql_fetch_array($result)) > { > ?> > <tr > > <td ><?php echo $counter;?></td> > <td ><?php echo $row["syard"];?></td> > <td ><?php echo $row["street"];?></td> > <td ><?php echo $row["phase"];?></td> > <td ><?php echo $row["unit"];?></td> > <td ><?php echo $row["catagory"];?></td> > <td ><?php echo $row["price"];?></td> > <td><?php echo $row["comments"];?></td> > </tr> > <?php > $counter = $counter + 1; > } > mysql_close($con); > ?> > </table> > </td> > </tr> > </table> > </body> > </html> >
I'm not seeing anything wrong with this. Are you sure that the query that you are sending is returning more than 1 record? I suggest echo $mySQL; exit; just before the query and make sure you are getting the expected sql statement & paste that into a mysql client to verify that you are getting the expected results. If you are, we can delve deeper into the php, but at first glance, I don't see anything wrong with the php. I also suggest using a database handle wherever you are setting up the connect: $db = mysql_connect('host','user','pass'); Then where you are doing the query, change it to: $result = mysql_query($mySQL,$db) or die(mysql_error($db)); Adding the $db is invaluable if anywhere in your code you happen to be connecting to another mysql server. $db will make sure that you are connecting to the server you want. <code change suggestions> You may want to change the include "connection.php" to a require("connection.php"). Include will not fail if it can't find the file, require will. I would use mysql_fetch_assoc instead of mysql_fetch_array. It's not a big deal but if you are using the field names it is a bit less for PHP and MySQL to do. I also would change $counter=$counter + 1; to $counter++; </code change suggestions> bp