•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,701 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,166 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 4319 | Replies: 7
![]() |
•
•
Join Date: Oct 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hi every one,
I have a little problem in php.
problem is that i want to search mysql table by php coding.
In php i want to use Drop down menu And a text field.
I have mysql table name is guestbook, now i use two entries
in dropdown menu (By Id,By name).and in the search text area
i type the any name selecting by name fom dropdown menu and then click on search button. Then it gave me the result in table format.
i Want the code for php how to retrieve data and what is the coding
for html form (Dropdown menu,text box,search button).
Can any one help me
Thanks.
I have a little problem in php.
problem is that i want to search mysql table by php coding.
In php i want to use Drop down menu And a text field.
I have mysql table name is guestbook, now i use two entries
in dropdown menu (By Id,By name).and in the search text area
i type the any name selecting by name fom dropdown menu and then click on search button. Then it gave me the result in table format.
i Want the code for php how to retrieve data and what is the coding
for html form (Dropdown menu,text box,search button).
Can any one help me
Thanks.
so write it, theres not much to it.
1. need a db connection and database structure
2. need a form
3. need to wite some sql
4. need to format the html
look around, you will probibly find some examples or tutorials out there.
1. need a db connection and database structure
2. need a form
3. need to wite some sql
4. need to format the html
look around, you will probibly find some examples or tutorials out there.
Last edited by tgreer : Oct 6th, 2006 at 4:33 pm. Reason: Removed unnecessary quote block.
If you have a specific question, yes I will help. If you want to hire a programmer then post in the jobs section.
Otherwise do your homework, and use google,yahoo,ask.com there are millions of sites out there that have tutorials and samples including this one.
Otherwise do your homework, and use google,yahoo,ask.com there are millions of sites out there that have tutorials and samples including this one.
Last edited by tgreer : Oct 6th, 2006 at 4:32 pm. Reason: Removed unnecessary quote block.
•
•
Join Date: Oct 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
thanks for reply.
ok
I have html page coding:
[html]<h2>Search</h2>
<form name="search" method="post" action="Search.php">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="fname">First Name</option>
<Option VALUE="lname">Last Name</option>
<Option VALUE="info">Profile</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>[/html]
Now Php Which have to search the database & Print results.
[php]<?
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
$data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");
while($result = mysql_fetch_array( $data ))
{
echo $result['fname'];
echo " ";
echo $result['lname'];
echo "<br>";
echo $result['info'];
echo "<br>";
echo "<br>";
}
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
echo "<b>Searched For:</b> " .$find;
}
?>[/php]
The problem is that it cannot display the Results.
Whats wrong with this code.
Can u help me.
Thanks.
ok
I have html page coding:
[html]<h2>Search</h2>
<form name="search" method="post" action="Search.php">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="fname">First Name</option>
<Option VALUE="lname">Last Name</option>
<Option VALUE="info">Profile</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>[/html]
Now Php Which have to search the database & Print results.
[php]<?
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
$data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'");
while($result = mysql_fetch_array( $data ))
{
echo $result['fname'];
echo " ";
echo $result['lname'];
echo "<br>";
echo $result['info'];
echo "<br>";
echo "<br>";
}
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
echo "<b>Searched For:</b> " .$find;
}
?>[/php]
The problem is that it cannot display the Results.
Whats wrong with this code.
Can u help me.
Thanks.
Last edited by tgreer : Oct 6th, 2006 at 11:36 am. Reason: Added code tags.
Are you getting an error or just no data returned?
try this
Looks like you put the find variable inside of single quotes which treat it as literal. mysql is looking for $find and not the contents of that variable.
The die function will exit the script and echo out the query, if it looks good then comment out the die and continue.
try this
$sql = "SELECT * FROM users WHERE upper($field) LIKE'%".$find."%'" die($sql); $data = mysql_query($sql);
Looks like you put the find variable inside of single quotes which treat it as literal. mysql is looking for $find and not the contents of that variable.
The die function will exit the script and echo out the query, if it looks good then comment out the die and continue.
Last edited by tgreer : Oct 6th, 2006 at 4:32 pm. Reason: Removed unnecessary quote block.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- PHP mysql drop down populates another drop down (PHP)
- for validation - text box and drop down menu (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: PHP includes & variables
- Next Thread: Help with Joomla Component


Linear Mode