Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Mon Jan 28, 2008 9:50 am Reply with quote

I need to capture the year from a field such as:

Quote:
2008-01-17 13:02:07


Then use this value in a query to view only those records for that year.

I have a list box such as
Code:


Opentable();
echo"<tr><center>Use drop down box to view prior years questions.</center></tr>";
echo"<tr><center>Select Year <select name='year' size=\"1\" onchange=\"reload(this.form)\">";
   echo"<option value=\"2007\" selected>2007</option>"
   ."<option value=\"2008\">2008</option>"
   ."<option value=\"2009\">2009</option>"
   ."<option value=\"2010\">2010</option>"   
   ."</select></center></tr>"
   ."</form>";   
Closetable();


So I can choose last year and use that in a query to view just those records.
Code:


$result = $db->sql_query("SELECT SUBSTRING(cm.time,4) AS qyear, * FROM comments cm
   JOIN course cs ON (cm.course_id = cs.course_id)
   JOIN reply r ON (cm.cid = r.cid)
   WHERE cm.course_id = '$course_id'
   AND qyear = '$year'
   ORDER BY cm.time DESC");   
 
View user's profile Send private message Visit poster's website ICQ Number
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Mon Jan 28, 2008 10:21 am Reply with quote

I would think the YEAR() function would be a better choice than SUBSTRING().

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
Donovan







PostPosted: Mon Jan 28, 2008 10:55 am Reply with quote

Gremmie wrote:
I would think the YEAR() function would be a better choice than SUBSTRING().


Your right. And since it is DATETIME I can use that instead.

I still have to figure out the proper structure of the query to read the value of the list box.

Code:
echo"<tr><center>Use drop down box to view prior years questions.</center></tr>";

echo"<tr><center>Select Year <select name=\"year\" size=\"1\" onchange=\"document.forms[0].submit();\">";
   echo"<option value=\"2007\">2007</option>"
   ."<option value=\"2008\"selected>2008</option>"
   ."<option value=\"2009\">2009</option>"
   ."<option value=\"2010\">2010</option>"   
   ."</select></center></tr>"
   ."</form>";   

$result = $db->sql_query("SELECT YEAR(cm.time) AS qyear, * FROM comments cm
   JOIN course cs ON (cm.course_id = cs.course_id)
   JOIN reply r ON (cm.cid = r.cid)
   WHERE cm.course_id = '$course_id'
   AND qyear = '$year'
   ORDER BY cm.time DESC");   
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©