bschultz Posted March 21, 2007 Share Posted March 21, 2007 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 https://forums.phpfreaks.com/topic/43713-solved-question-about-multiple-where-clauses/ Share on other sites More sharing options...
cmgmyr Posted March 21, 2007 Share Posted March 21, 2007 try: $sql = "SELECT date, type, event, action, comments FROM cancellations WHERE type = 'school' AND date = CURDATE() "; Link to comment https://forums.phpfreaks.com/topic/43713-solved-question-about-multiple-where-clauses/#findComment-212218 Share on other sites More sharing options...
bschultz Posted March 21, 2007 Author Share Posted March 21, 2007 Thank you! I should I figured out that using quotes around CURDATE() would look for text, not the mysql command! Thanks again! Link to comment https://forums.phpfreaks.com/topic/43713-solved-question-about-multiple-where-clauses/#findComment-212221 Share on other sites More sharing options...
cmgmyr Posted March 21, 2007 Share Posted March 21, 2007 no problem Link to comment https://forums.phpfreaks.com/topic/43713-solved-question-about-multiple-where-clauses/#findComment-212222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.