lauralee Posted October 7, 2012 Share Posted October 7, 2012 Currently in my code I select the current month and future months to be shown on the calendar. I want to be able to have only the current month and future months shown automatically using the date function. Below is my code. How do I change the WHERE mo_id>09 in the code so that I don't have to change it manually every month and the only the current month and future months will display, not all of the month's names? $sql = @mysql_query('SELECT mo_id, month_name FROM month WHERE mo_id>09 ORDER BY mo_id'); if (!$sql) {exit('<p>Error performing query: ' . mysql_error() . '</p>');}while ($mos = mysql_fetch_array($sql)) { echo '<h2>' . $mos['month_name'] . '</h2><br />'; $items = @mysql_query('SELECT *FROM calendar WHERE mo ="' . $mos['month_name'] . '" OR "' . $mos['dt'] . '" ORDER BY dt, am_pm, hr, min'); if (!$items) {exit('<p>Error performing query: ' . mysql_error() . '</p>');}while ($each = mysql_fetch_array($items)) {echo '<p><em>' . $each['mo'] . ' ' . $each['dt'] . ' </em>' . $each['hr'] . ':' . $each['min'] . ' ' . $each['am_pm'] . ' - <span>' . $each['location'] . ' - ' . $each['title'] . '</span> - ' . $each['event'] . '</p>';}}?> Link to comment Share on other sites More sharing options...
niche Posted October 7, 2012 Share Posted October 7, 2012 (edited) That's easy: WHERE mo_id> " . $var . " ORDER BY assuming $var is a numeric else WHERE mo_id> " . '$var' . " ORDER BY Edited October 7, 2012 by niche Link to comment Share on other sites More sharing options...
oldscholar Posted October 12, 2012 Share Posted October 12, 2012 I think the most appropriate quesry is as follow: $sql = @mysql_query('SELECT mo_id, month_name FROM month WHERE mo_id >= MONTH(CURDATE()) ORDER BY mo_id'); You'll get the current date and the current month in numeric representation. Link to comment Share on other sites More sharing options...
JohnTipperton Posted October 18, 2012 Share Posted October 18, 2012 (edited) $sql = @mysql_query('SELECT mo_id, month_name FROM month WHERE mo_id>09 ORDER BY mo_id'); change it to <form method="post" name="form1"><select name="month" id="month"> <option selected="selected" value="01">01</option> <option value="02">02</option> <option value="03">03</option> <option value="04">04</option> <option value="05">05</option> <option value="06">06</option> <option value="07">07</option> <option value="08">08</option> <option value="09">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </select><input type="submit" value="Post"></form> $month = $_POST['month]; $sql = @mysql_query('SELECT mo_id, month_name FROM month WHERE mo_id>'.$month.'ORDER BY mo_id'); Edited October 19, 2012 by JohnTipperton Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now