Re: [PHP-DB] Wildcards
Morten Nielsen wrote: $qid =db_query( SELECT ID, NAME, ADDRESS FROM users WHERE ID=* AND NAME='John' ); Is it somehow possible to have a wildcard, so it returns all records, where the name is john and the ID is not important? If you don't care about the ID, why include it? SELECT id, name, address FROM users where NAME='John' That will return all records whose NAME='John', regardless of anything else. -- W | I haven't lost my mind; it's backed up on tape somewhere. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / WebSmith . 800.441.3873 x130 Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Wildcards
That query doesn't make sense... All you are looking for is to get a resultset containing ONLY the rows where name is John. So, just write: SELECT ID, NAME, ADDRESS FROM users WHERE NAME='John'; By the way, in SQL, the wildcard character for regular expressions is the '%' not '*' . Gurhan -Original Message- From: Morten Nielsen [mailto:[EMAIL PROTECTED]] Sent: Monday, May 06, 2002 4:46 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Wildcards Hi, I am trying to make a SELECT command like this: $qid =db_query( SELECT ID, NAME, ADDRESS FROM users WHERE ID=* AND NAME='John' ); Is it somehow possible to have a wildcard, so it returns all records, where the name is john and the ID is not important? Regards, Morten -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Wildcards
Hi, I am trying to make a SELECT command like this: $qid =db_query( SELECT ID, NAME, ADDRESS FROM users WHERE ID=* AND NAME='John' ); Is it somehow possible to have a wildcard, so it returns all records, where the name is john and the ID is not important? Well for a query like that just omit ID= $qid = db_query(SELECT ID, NAME, ADDRESS FROM users WHERE Name = 'John'); It will still find all the records you want and only uses Name as the condition. However yes it is possible to use wildcards...MOST databases support it but you'll need to check with your db distributor to know for sure. Typically the wildcard is % (an equivalent to * as a wild card)...some DBs also support ? as a one character wild card...however to use them you have to use the LIKE function. So say if you wanted to find queries WHERE the name started with an A $qid = db_query(SELECT ID, NAME, ADDRESS FROM users WHERE Name LIKE 'A%'); Sincerely, Craig Vincent -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Wildcards
Hi, Just make a sql string testing the keys you are interested: $sql = SELECT ID, NAME, ADDRESS FROM users WHERE; $where = '; if (isset($id) ) $where . = id = $id; // LOOK AT . CONCATENATION OPERATOR if (isset($name)) if ($where) $where .= AND name='$name' else $where = name='$name'; if (isset($other)) if($where) $where .= AND other='$other' else $where = other='$other'; mysql_query($sql.$where). - Original Message - From: Gurhan Ozen [EMAIL PROTECTED] To: Morten Nielsen [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, May 06, 2002 5:41 PM Subject: RE: [PHP-DB] Wildcards That query doesn't make sense... All you are looking for is to get a resultset containing ONLY the rows where name is John. So, just write: SELECT ID, NAME, ADDRESS FROM users WHERE NAME='John'; By the way, in SQL, the wildcard character for regular expressions is the '%' not '*' . Gurhan -Original Message- From: Morten Nielsen [mailto:[EMAIL PROTECTED]] Sent: Monday, May 06, 2002 4:46 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Wildcards Hi, I am trying to make a SELECT command like this: $qid =db_query( SELECT ID, NAME, ADDRESS FROM users WHERE ID=* AND NAME='John' ); Is it somehow possible to have a wildcard, so it returns all records, where the name is john and the ID is not important? Regards, Morten -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php