PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
Donovan
Client


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

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

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: 2401
Location: Iowa, USA

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

I would think the YEAR() function would be a better choice than SUBSTRING().
View user's profile Send private message
Donovan
Client


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

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

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");   
View user's profile Send private message Visit poster's website ICQ Number
Display posts from previous:       
Post new topic   Reply to topic

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
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2008 by Raven
Proud to be listed at Lobo Links Web Directory

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::

:: fisubice Theme Recoded To 100% W3C CSS & HTML 4.01 Transitional Compliance by Raven and 64bitguy ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum