mattkirtley Posted July 20, 2009 Share Posted July 20, 2009 Hi, Im a newbie to PHP and SQL and wondered if someone would helpful enough to point me in the right direction? I have a page which is currently returning data from a table fine, i've intoduced a search field which is working great on its own i've pasted the code below.... However i want to intoduce a second field which could be searched in, i would like them to work independantly of each other, i have pasted the code i doctored at the bottom, the issue is that i cannot search in the 'city' field on its own without having to fill in the 'venue_name' field ??? $colname_venue = "%"; if (isset($_POST['venue_name'])) { $colname_venue = $_POST['venue_name']; } mysql_select_db($database_brsenter_BRS, $brsenter_BRS); $query_venue = sprintf("SELECT id, venue_name, city, first_name, last_name, telephone, email1, web_url FROM VENUE WHERE venue_name LIKE %s", GetSQLValueString("%" . $colname_venue . "%", "text")); $query_limit_venue = sprintf("%s LIMIT %d, %d", $query_venue, $startRow_venue, $maxRows_venue); $venue = mysql_query($query_limit_venue, $brsenter_BRS) or die(mysql_error()); $row_venue = mysql_fetch_assoc($venue); -------------------------------------------------------------------------------- $colname_venue = "%"; if (isset($_POST['city'])) { $colname_venue = $_POST['city']; } $colname2_venue = "%"; if (isset($_POST['venue_name'])) { $colname2_venue = $_POST['venue_name']; } mysql_select_db($database_brsenter_BRS, $brsenter_BRS); $query_venue = sprintf("SELECT id, venue_name, city, first_name, last_name, telephone, email1, web_url FROM VENUE WHERE city LIKE %s OR venue_name LIKE %s", GetSQLValueString("%" . $colname_venue . "%", "text"),GetSQLValueString("%" . $colname2_venue . "%", "text")); $query_limit_venue = sprintf("%s LIMIT %d, %d", $query_venue, $startRow_venue, $maxRows_venue); $venue = mysql_query($query_limit_venue, $brsenter_BRS) or die(mysql_error()); $row_venue = mysql_fetch_assoc($venue); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/166642-php-and-mysql-searches/ Share on other sites More sharing options...
HPWebSolutions Posted July 21, 2009 Share Posted July 21, 2009 In the second set of code, under the dashed line, It looks like your value for city is still the value of venue, is that what you mean to do? Also, when you take the OR venue.... out of the query, are you also removing the second parameter "GetSQLValueString("%" . $colname2_venue . "%", "text")"? Quote Link to comment https://forums.phpfreaks.com/topic/166642-php-and-mysql-searches/#findComment-879270 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.