bschultz Posted March 22, 2007 Share Posted March 22, 2007 I'm trying to implement a weather cancellation script. A user can enter in a cancellation (school, business, meeting, sports event) because of the weather, and it will display on a main page. The script is working to a certain extent. There are several categories that I'm displaying on the page. As long as there are records that match, it works just fine. If one select statement returns "false" it halts the remainder of the script. So, in the code below, if the first select returns false, the second statement won't run. Can someone tell me where my code is wrong? Thanks. <p><strong>Schools Closed Today</strong><br> <?php $conn1 = mysql_connect("localhost", "username", "password"); if (!$conn1) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("cancellations")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql1 = "SELECT date, type, event, action, comments FROM cancellations WHERE type = 'school' AND action = 'closed' AND date = CURDATE() "; $result1 = mysql_query($sql1); if (!$result1) { echo "Could not successfully run query ($sql1) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result1) == 0) { echo "</strong>There aren't any schools closed 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 ($row1 = mysql_fetch_assoc($result1)) { echo $row1["event"]; echo " "; echo $row1["comments"]; echo "<br>"; } mysql_free_result($result1); ?> </p> <p><strong>Schools Running Two Hours Late Today</strong><br> <?php $conn2 = mysql_connect("localhost", "username", "password"); if (!$conn2) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("cancellations")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql2 = "SELECT date, type, event, action, comments FROM cancellations WHERE type = 'school' AND action = '2 Hours Late' AND date = CURDATE() "; $result2 = mysql_query($sql2); if (!$result2) { echo "Could not successfully run query ($sql2) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result2) == 0) { echo "</strong>There aren't any schools running 2 hours late 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 ($row2 = mysql_fetch_assoc($result2)) { echo $row2["event"]; echo " "; echo $row2["comments"]; echo "<br>"; } mysql_free_result($result2); ?> Quote Link to comment https://forums.phpfreaks.com/topic/43833-solved-multiple-selects-in-1-browser-page/ Share on other sites More sharing options...
fenway Posted March 22, 2007 Share Posted March 22, 2007 Well, you have exit statements lying around... and why should they ever return false? Isn't no records still a valid result set with no length? Quote Link to comment https://forums.phpfreaks.com/topic/43833-solved-multiple-selects-in-1-browser-page/#findComment-212894 Share on other sites More sharing options...
bschultz Posted March 22, 2007 Author Share Posted March 22, 2007 Thank you! Call me stupid! What works for ONE statement, doesn't always work for TWO! Quote Link to comment https://forums.phpfreaks.com/topic/43833-solved-multiple-selects-in-1-browser-page/#findComment-212967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.