RE: REGEXP and Variables.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----Original Message-----
From: Shannon Doyle [mailto:shannon@wyattgroup.com.au] 
Sent: Thursday, October 09, 2003 1:19 AM
To: php-db@lists.php.net
Subject: REGEXP and Variables.

Hi People,

Need a little assistance with the following MySQL query:-

$query = "SELECT employ_id,company FROM employers WHERE employ_id REGEXP
'($employ_id)' OR company REGEXP '($name)' OR industry REGEXP
'($industry)'"; 
 
The above query gets the variables $employ_id, $name and $industry from
a search box on a previous page. I can confirm that the variables are
being parsed to the query.

The problem is that the above query appears to match everything in the
table, from any of the fields and thus just dumps out the entire
contents of the table, instead of only selecting the ones that match the
search criteria. 

Basically I have a variable passed to the query and it must return the
values from the table that have the variable in its entirety somewhere
in the fields value.


In addition to this, once I have it selecting the correct values and
returning them to me. What can I do to show a 'No Results' situation?

Any help woul dbe gratly appreciated.

Cheers,

Shannon
------------------------------------------------------------------------
---
	I'm not sure why your query returns the whole table but it is
most likely a problem with your regular expression. I would suggest
posting regular expressions that you are using and an example of some
values that it is matching that you don't want it to match.
	As for handling the no results situation you can do the
following.

if(!$result = mysql_query($query)) {
	echo("could not query the database");
} else {
	if(mysql_num_rows($result) == 0)
		echo("No records found");
}
good luck
	Jeremy

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux