suttercain Posted February 26, 2007 Share Posted February 26, 2007 Good Morning, Right now I have a table being echoed that has three columns: division, fuel and disp. On the mysql end I have about 2000 vehicles. Some 2007 and some 2008. The year data is already in the table but I would like to only echo the 2007 vehicles. Does anyone no how I can exclude the 2008 or have it only include the 2007? Would this be done on via the mysql_query? Here is the code if needed: <?php //Connect to the Database via the Include File! require ('get_connected.php'); // Perform a statndard SQL query: $res = mysql_query("SELECT UPPER(division) AS division, sub_model, disp, fuel FROM vlist_2007 ORDER BY division ASC") or die (mysql_error()); // Convert the Array DIVISION to Full Names $makes = array('ACUR'=>'ACURA', 'ALP'=>'ALPINA', 'ASMA'=>'ASMA', 'AUDI'=>'AUDI'); print $makes[$row['division']]; //CSS for the Alternating Color Rows $class = 'even'; //Convert DIVISION Column to out put from the MySQL instead of HTML $current = ''; while($row = mysql_fetch_array($res)) { if($current != $row['division']) { $current = $row['division']; echo "<table width='100%' border='0' bgcolor=#CCCCCC cellpadding='1' cellspacing='1'> <tr> <td width='110'><b>$makes[$current]</b></td> <td width='110'><b>FUEL</b></td> <td width='110'><b>DISPLACEMENT</b></td> </tr>"; } //Continuation of CSS for the Alternating Color Rows $class = $class == 'even' ? 'odd' : 'even'; //Populate the Tables from the Database echo "<tr class=\"$class\">\n"; echo "<td>$row[sub_model]</td>\n"; echo "<td>$row[disp]</td>\n"; echo "<td>$row[fuel]</td>\n"; echo "</tr>\n"; } ?> Thanks in advance. Shannon Quote Link to comment https://forums.phpfreaks.com/topic/40190-solved-exclude-certain-years-from-a-mysql-table-column/ Share on other sites More sharing options...
monk.e.boy Posted February 26, 2007 Share Posted February 26, 2007 SELECT UPPER(division) AS division, sub_model, disp, fuel FROM vlist_2007 WHERE YEAR( datetime ) = 2007 ORDER BY division ASC Use the YEAR function like above, I don't know what your model year datetime column is called, so I called it datetime. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html monk.e.boy Quote Link to comment https://forums.phpfreaks.com/topic/40190-solved-exclude-certain-years-from-a-mysql-table-column/#findComment-194429 Share on other sites More sharing options...
suttercain Posted February 26, 2007 Author Share Posted February 26, 2007 Hi and thank you for the reply, I gave it a shot and ran the following code: // Perform a statndard SQL query: $res = mysql_query("SELECT UPPER(division) AS division, sub_model, disp, fuel, veh_class, arb_std, test_group, eo FROM vlist_2007 WHERE YEAR(year)=2007 ORDER BY division ASC") or die (mysql_error()); The column in which the year resides is titled "year." When I ran the above code I got a blank white page. Quote Link to comment https://forums.phpfreaks.com/topic/40190-solved-exclude-certain-years-from-a-mysql-table-column/#findComment-194436 Share on other sites More sharing options...
craygo Posted February 26, 2007 Share Posted February 26, 2007 does your year column only have the year ie 2007?? If it does then just use WHERE year = '2007' if you use YEAR(year) then mysql will assume the `year` field is a timestamp or actual date field containing month, day, year data. Ray Quote Link to comment https://forums.phpfreaks.com/topic/40190-solved-exclude-certain-years-from-a-mysql-table-column/#findComment-194460 Share on other sites More sharing options...
suttercain Posted February 26, 2007 Author Share Posted February 26, 2007 In the year column it has both 2007 and 2008. I need it to only echo those vehicles that are 2007. Quote Link to comment https://forums.phpfreaks.com/topic/40190-solved-exclude-certain-years-from-a-mysql-table-column/#findComment-194469 Share on other sites More sharing options...
suttercain Posted February 26, 2007 Author Share Posted February 26, 2007 Awesome. It worked. Quote Link to comment https://forums.phpfreaks.com/topic/40190-solved-exclude-certain-years-from-a-mysql-table-column/#findComment-194471 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.