Jump to content

[SOLVED] Searching multiple mysql columns


duduwudu

Recommended Posts

Hello, I'm currently building a database of local businesses, I'm quite new to using php and mysql. While I'm mostly managing to stumble my through it, a couple of things are confusing me. This is one of the things. If anyone can help, that would be really great.

 

Ok, so I've build a search page, and a results page and it works great but there is one problem. Currently it will only search through the 'name' column, but I'd also like it to search through the 'type' column at the same time.

 

This is the code I'm using to fetch the results

$colname_Businesses = "-1";
if (isset($_POST['search_par'])) {
  $colname_Businesses = $_POST['search_par'];
}
mysql_select_db($database_HBBA_DATABASE, $HBBA_DATABASE);
$query_Businesses = sprintf("SELECT * FROM Businesses WHERE name LIKE %s", GetSQLValueString("%" . $colname_Businesses . "%", "text"));
$query_limit_Businesses = sprintf("%s LIMIT %d, %d", $query_Businesses, $startRow_Businesses, $maxRows_Businesses);
$Businesses = mysql_query($query_limit_Businesses, $HBBA_DATABASE) or die(mysql_error());
$row_Businesses = mysql_fetch_assoc($Businesses);

 

I'm not sure what to add in to make it also search through the 'type' column or where to put that. Can anyone point me in the right direction? Any help would be most appreciated.

 

Cheers

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/63902-solved-searching-multiple-mysql-columns/
Share on other sites

just 1 value to search for in both columns.

 

so, if i was searching for the word 'book' it would return any entries from names with the work book in (like 'the book case') and any entries form the type column with the work book in (like 'book restoration')

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.