Page 1 of 1

Search from MySQL Table and display result in HTML Table

Posted: Fri May 13, 2011 6:39 pm
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.

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

Posted: Sat May 14, 2011 6:10 pm
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'");