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

 

Archived

This topic is now archived and is closed to further replies.

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