smti Posted May 18, 2009 Share Posted May 18, 2009 Hi, I need help pulling the value produced from an SQL query. I will explain, but here is the code: <? include("includes/calendarconnection.inc.php"); ?> <? $today=date("m.d.y"); $result = mysql_query("SELECT * FROM $tbl_name where event_date=curdate()"); $eventstoday = mysql_num_rows($result); echo $eventstoday; echo "<br>"; if ($eventstoday==0){ echo "No events today, execute query for date in two days"; $newdate = mysql_query("Select date_add(curdate(), interval 2 day"); echo $newdate; } else { // Retrieve data from database $sql="SELECT * FROM $tbl_name where event_date=curdate() limit 1"; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ echo $rows ['event_date']; echo "<br>"; echo $rows ['event_title']; echo "<br>"; echo $rows ['event_desc']; } // close while loop } // close connection mysql_close(); Essentially, I need help with the IF statement: if ($eventstoday==0){ echo "No events today, execute query for date in two days"; $newdate = mysql_query("Select date_add(curdate(), interval 2 day"); echo $newdate; } I need to execute the new date query and then echo the date provided by the query. I tried just performing the query and then echoing, but this does not seem to work. Do I need to add a "fetch row query"? Any help you can provide would be much appreciated. Thank You, smti Link to comment https://forums.phpfreaks.com/topic/158643-help-with-date-query/ Share on other sites More sharing options...
Ken2k7 Posted May 18, 2009 Share Posted May 18, 2009 Yeah, you need to fetch the row first, but that SQL won't do much except tell you the date. Did you mean something like this - $newdate = mysql_query("SELECT * FROM $tbl_name WHERE DATE_ADD(CURDATE(), INTERVAL 2 DAY) >= event_date"); ? Link to comment https://forums.phpfreaks.com/topic/158643-help-with-date-query/#findComment-836688 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.