Search from MySQL Table and display result in HTML Table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ravikiran
Forum Newbie
Posts: 2
Joined: Tue Sep 16, 2008 1:45 am

Search from MySQL Table and display result in HTML Table

Post by ravikiran »

Hi,

I need PHP code to help me with the following stuff:
1. I have a MySQL table with addresses split into 4 fields.
2. I need a search functionality which can search the MySQL table in 2 of the fields, fetch all the relative addresses and display them in an HTML table.
3. I'll have only one field in which I can enter the search keyword.

Thanks in advance,

Regards,
Ravi.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Search from MySQL Table and display result in HTML Table

Post by Christopher »

For #2, you should look at the examples in the PHP manual for the query() functions for the database connector you are using (e.g. PDO).

For #3, you can search multiple fields with a search term in SQL:

Code: Select all

$search = $db->escape($_POST['search']);
$result = $db->query("SELECT * FROM mytable WHERE foo='$search' OR bar='$search'");
(#10850)
Post Reply