DBookatay Posted February 5, 2011 Share Posted February 5, 2011 I have a script that pulls data from my dB based on the year selected from 2006 - 2011, and if no year is selected it automatically loads the current year, 2011. I have a css that changes the design of the "tab" based on the year selected, but how do I make it so that the "On" style reflects the current year tab if no year is selected? Confused yet? I created an image of what I mean as well as the php script. if ($_GET['date']) {$year = ($_GET['date']);} else {$year = date("Y");} $query = "select DISTINCT YEAR(sold_date) AS `sold_date` FROM Sold WHERE sold_date ORDER BY sold_date DESC"; $result = mysql_query($query); $numrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ $year = $row['sold_date']; if ($_GET['date'] == $year) { $class = "On"; } elseif ($_GET['date'] != $year) { $class = ""; } $miniNav .= '<a class="'.$class.'" href="index.php?date='.$year.'">'.$year.'</a>'; } [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 5, 2011 Share Posted February 5, 2011 Before the loop, if the $_GET var is empty, assign 2011 to it. if( empty($_GET['date']) ) { $_GET['date'] = 2011; } Quote Link to comment Share on other sites More sharing options...
DBookatay Posted February 5, 2011 Author Share Posted February 5, 2011 Before the loop, if the $_GET var is empty, assign 2011 to it. if( empty($_GET['date']) ) { $_GET['date'] = 2011; } Wow that easy hunh? Thanks! Quote Link to comment 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.