Re: Managing Multiple Conditions in a MySQL Query
| From: | Sam Leibowitz | Date: | Wed, 02 May 2001 18:14:25 +0000 |
| Subject: | Re: Managing Multiple Conditions in a MySQL Query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-51169@lists.php.net to get a copy of this message | ||
Well, first of all, you can start by getting friendly with "print
mysql_error();", which will tell you if you have any syntax errors in your
SQL statement. =D
And I think you do. That should be:
...WHERE Public='yes' AND Verified='yes'...
As opposed to:
...WHERE Public='yes',Verified='yes'...
Additionally, you're passing your results directly to a while loop, which
is a something of a no-no. Even if your SQL statement is perfectly
formatted, you'll generate a warning if the number of rows returned is
zero.
Sam Leibowitz (sleibowitz@btcwcu.org)
Project Manager
Business Technology Center (http://www.btcwcu.org)
On Wed, 2 May 2001, Mike Gifford wrote:
> Hello,
>
> I'd like to verify two conditions are true in the results that I pull out of my
> MySQL database. In this case I wanted Verified and Public both to be listed as
> 'yes' in the DB before they were displayed. The code I tried to use is as follows:
>
> <?php
> echo "<p>Recent Signatures\n<br><em><UL>";
> $individuals_query = mysql_query("SELECT FirstName,LastName,CityState FROM
> phPetition WHERE Public='yes',Verified='yes' ORDER BY ID DESC LIMIT
> 0,5");
> while ($individuals_array = mysql_fetch_array($individuals_query)) {
> echo "<LI>" . stripslashes($individuals_array["FirstName"]) . "
> " .
> stripslashes($individuals_array["LastName"]) . " from " .
> stripslashes($individuals_array["CityState"]);
> }
>
> However, it gave me the following error:
>
> Warning: Supplied argument is not a valid MySQL result resource in
> /usr/local/rabble/petition/index.php3 on line 89
>
> How do I get around this?
>
> Mike
> --
> Mike Gifford, OpenConcept Consulting, http://openconcept.ca
> Offering everything your organization needs for an effective web site.
> Featured Client: http://rabble.ca - News For the Rest of Us!
> Courage my friends, 'tis not too late to make a better world - T. Douglas
>
>