Jump to content

[SOLVED] Question about multiple WHERE clauses


bschultz

Recommended Posts

I might be barking up the wrong tree, but I can't find much on Google about the syntax of a multiple WHERE statement.  Here's my code:

 

<?php

$conn = mysql_connect("localhost", "username", "password");

if (!$conn) {
   echo "Unable to connect to DB: " . mysql_error();
   exit;
}

if (!mysql_select_db("cancellations")) {
   echo "Unable to select mydbname: " . mysql_error();
   exit;
}
$sql = "SELECT date, type, event, action, comments FROM cancellations WHERE (type = 'school' AND date = 'CURDATE()' )";

$result = mysql_query($sql);

if (!$result) {
   echo "Could not successfully run query ($sql) from DB: " . mysql_error();
   exit;
}

if (mysql_num_rows($result) == 0) {
   
echo "</strong></br>There aren't any weather realated announcements for today!";
   exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop


while ($row = mysql_fetch_assoc($result)) {

   echo $row["event"];
   echo $row["action"];
   echo $row["comments"];
   echo "<br>";
}

mysql_free_result($result);

?>

 

On the line:

 

$sql = "SELECT date, type, event, action, comments FROM cancellations WHERE (type = 'school' AND date = 'CURDATE()' )";

 

I can remove the second clause, and the code works just fine.  Can someone please point me in the right direction on a multiple WHERE syntax?

 

Thanks.

 

Brian

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.