Bendude14 Posted July 18, 2008 Share Posted July 18, 2008 Ok i have this code that queries my database and prints out the latest results... The problem is at the moment i can only get it to print out the one set of results but i would like it to print out the results from the last month... Can it be done with out duplicating this code and then setting the $seconds variable to 1week 2 week etc. Thanks in advance <?php $sql = "SELECT win_team, lose_team, win_score, lose_score FROM results WHERE time > NOW()- $seconds LIMIT 1"; $result = mysql_query($sql) or trigger_error('Query failed: '. mysql_error()); ?><table cellpadding="5px"> <?php while($dbarray = mysql_fetch_array($result)){ echo "<td style=\"font-weight:bold;\">".$dbarray['win_team']."</td>"; $win_team = $dbarray['win_team']; echo "<td> </td>"; echo "<td style=\"font-weight:bold;\">".$dbarray['win_score']."</td>"; echo "<td> </td>"; echo "<td style=\"font-weight:bold;\">".$dbarray['lose_score']."</td>"; echo "<td> </td>"; echo "<td style=\"font-weight:bold;\">".$dbarray['lose_team']."</td>"; $lose_team = $dbarray['lose_team']; } $sql2 = "SELECT player1, player2, player3, player4, player5, player6 FROM teams WHERE team_name = '$win_team'"; $result2 = mysql_query($sql2) or trigger_error('Query failed: '. mysql_error()); $result2 = mysql_fetch_row($result2) or trigger_error('Query failed: '. mysql_error()); $sql3 = "SELECT player1, player2, player3, player4, player5, player6 FROM teams WHERE team_name = '$lose_team'"; $result3 = mysql_query($sql3) or trigger_error('Query failed: '. mysql_error()); $result3 = mysql_fetch_row($result3) or trigger_error('Query failed: '. mysql_error()); $i = 0; foreach($result2 as $players) { echo "<tr><td>".$players."</td><td> </td><td> </td><td> </td><td> </td><td> </td> <td>".$result3[$i]."</td></tr>"; $i++; } ?> Quote Link to comment Share on other sites More sharing options...
marcus Posted July 18, 2008 Share Posted July 18, 2008 I suppose you can use switch as a method of viewing the latest records. <?php $from = $_GET['from']; function month(){ $m = ((date("m")-1) > 0) ? date("m")-1 : 12; $day = 86400; $to = 31*$day; $t = 30*$day; $ms = array(1 => $to, 2 => 28*$day, 3 => $to, 4 => $t, 5 => $to, 6 => $t, 7 => $to, 8 => $to, 9 => $t, 10 => $to, 11 => $t, 12 => $to); return $ms[$m]; } switch($from){ case 'week': $seconds = 7*86400; break; case 'biweek': $seconds = 14*86400; break; case 'month': $seconds = month(); break; } // your query ?> Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted July 18, 2008 Author Share Posted July 18, 2008 any other suggestions? i was thinking about changing my query to the database ideally? to compair against the timestamp already stored 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.