/    Sign up×
Community /Pin to ProfileBookmark

php search with mysql

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 . . .

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Bootsman123Jul 13.2005 — [code=php]
WHERE " . $s . " LIKE '%" . $q . "%'
[/code]


One thing you can always try is to echo the query.
×

Success!

Help @mahfooz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...