Jump to content

[SOLVED] Exclude certain years from a MySQL table column.


suttercain

Recommended Posts

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

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

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.