h1 to all…
i have problem with searching in mysql while using php.
i have written a code that is as follows, it is on two pages first is
search.php and 2nd is
result.php
the problem is that it shows only the first record from the table either it is id, name, father name, e-mail or address, or error message ” no result found”
i want to shoow all the record related to the search.
also my table has 7 fields as
id, name, f_name, mail, city, country, address and phone,
code is as follows:
[B][COLOR=Plum]
search.php
<html>
<body bgcoloe=”#806020″ color=”#FFFF00″>
<form medthod=”get” action=”file:///F|/EasyPHP/www/res.php”>
Enter ur keyword: <input type=”text” name=”srch” />
<?php
$link = mysql_connect(“localhost”, “root”, “”);
$field = mysql_list_fields(“phone”, “contact_info”, $link) or die(mysql_error());
$cols = mysql_num_fields($field);
echo “<select name=’feald’>”;
for( $i = 1; $i < $cols; $i++ ) {
echo “<option>” . mysql_field_name($field,$i) . “</option>”;
}
echo “</select>”;
?>
<input type=”submit” value=”Search”>
</form>
</body>
</html>
result.php
<?php
if(‘$submit’) {
$q = $_GET[‘srch’];
$s = $_GET[‘feald’];
$link = mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
$db = mysql_select_db(“phone”) or die(mysql_error());
$sql_query = mysql_query( ” SELECT * FROM contact_info WHERE ‘$s’ LIKE ‘%q%’ ” ) or die(mysql_error());
$check = mysql_num_rows($sql_query);
if($check == 1){
while( $res = mysql_fetch_array($sql_query) ){
echo $res[$s];
}
}
else
{
echo “no result found”;
}
}
?>
[/COLOR][/B]
thanx for any response . . .