Jump to content

PHP and MYSQL searches


mattkirtley

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/166642-php-and-mysql-searches/
Share on other sites

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")"?

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.