duduwudu Posted August 8, 2007 Share Posted August 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/63902-solved-searching-multiple-mysql-columns/ Share on other sites More sharing options...
micah1701 Posted August 8, 2007 Share Posted August 8, 2007 you mean like: SELECT * FROM table_name WHERE column1 = 'some_value' AND column2 = 'some_other_value' ??? Quote Link to comment https://forums.phpfreaks.com/topic/63902-solved-searching-multiple-mysql-columns/#findComment-318505 Share on other sites More sharing options...
duduwudu Posted August 8, 2007 Author Share Posted August 8, 2007 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') Quote Link to comment https://forums.phpfreaks.com/topic/63902-solved-searching-multiple-mysql-columns/#findComment-318508 Share on other sites More sharing options...
duduwudu Posted August 8, 2007 Author Share Posted August 8, 2007 Solved, it was really pretty simple in the end. Thanks anyway :D:D Quote Link to comment https://forums.phpfreaks.com/topic/63902-solved-searching-multiple-mysql-columns/#findComment-318526 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.