Re: Wildcards
| From: | Clever | Date: | Tue, 07 May 2002 01:03:58 +0000 |
| Subject: | Re: Wildcards | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-18999@lists.php.net to get a copy of this message | ||
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" <c-gurhan.ozen@wcom.com>
To: "Morten Nielsen" <mosgaard2000@hotmail.com>; <php-db@lists.php.net>
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:mosgaard2000@hotmail.com]
> Sent: Monday, May 06, 2002 4:46 PM
> To: php-db@lists.php.net
> 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
>