woolade Posted April 16, 2009 Share Posted April 16, 2009 Please bear with me as I'm new to this and not sure if this can even be done. I have a dropdown box that is populated from a field in a mysql database 'Season'. $query = "SELECT DISTINCT Season FROM Fixtures"; $result = mysql_query($query); echo '<select Season="Season_From_Fixtures">'; while( $row = mysql_fetch_array($result) ) { echo '<option>'.$row['Season'].'</option>'; } echo '</select>'; mysql_free_result( $result ); All the information on my page is based on a particular season, i.e. Season 1, Season 2 etc. The Season is initially selected from my SQL query; $query = "SELECT Fixtures.Season, Fixtures.Round, date_format(Fixtures.Date, '%D %b %Y' ) as GameDate, Teams.Name, Fixtures.WinLossDraw, Fixtures.OurGrossScore-Fixtures.OurWktsLost*6 AS OurNetScore, Fixtures.OppGrossScore-Fixtures. OppWktsLost*6 AS OppNetScore FROM Fixtures LEFT JOIN Teams ON Fixtures.vs_Teams_id = Teams.id WHERE Season = 1"; $result = mysql_query($query) or die(mysql_error()); At this stage the Season is selected within the code by typing the Season number, in the example above Season = 1, obviously this will need to be changed to a variable of some sort. How do I get my SQL query to re-run based on the Season selected from the dropdown box and then refresh the information on the page? I have searched this forum and the web but still can't seem to find the answer, is there a simple solution or does it involve a more complex way to go about it? FYI, this is the full code for my page; <html> <head> <link rel="stylesheet" type="text/css" href="phpthepests.css" /> <body> <h1>RESULTS - SEASON 1 - WINTER 2006</h1> <h1 class='small'>Click on Round Number to view Scorecard</h1> <?php $con = mysql_connect("localhost","xxxxxx","xxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxx_pests", $con); $query = "SELECT DISTINCT Season FROM Fixtures"; $result = mysql_query($query); echo '<select Season="Season_From_Fixtures">'; while( $row = mysql_fetch_array($result) ) { echo '<option>'.$row['Season'].'</option>'; } echo '</select>'; mysql_free_result( $result ); $query = "SELECT Fixtures.Season, Fixtures.Round, date_format(Fixtures.Date, '%D %b %Y' ) as GameDate, Teams.Name, Fixtures.WinLossDraw, Fixtures.OurGrossScore-Fixtures.OurWktsLost*6 AS OurNetScore, Fixtures.OppGrossScore-Fixtures. OppWktsLost*6 AS OppNetScore FROM Fixtures LEFT JOIN Teams ON Fixtures.vs_Teams_id = Teams.id WHERE Season = 1"; $result = mysql_query($query) or die(mysql_error()); $scd = 'http://www.xxxxxx.com.au/pests/scd'; echo "<table align=\"center\"> <tr> <th>Round</th> <th>Date</th> <th></th> <th></th> <th>Result</th> <th></th> <th></th> </tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align=\"center\"><a href='" . $scd . $row['Season'] . $row['Round'] . ".html'>" . $row['Round'] . "</a></td>"; echo "<td align=\"center\">" . $row['GameDate'] . "</td>"; echo "<td align=\"center\">" . "The Pests" . "</td>"; echo "<td class=\"grey\" align=\"center\">" . $row['OurNetScore'] . "</td>"; if($row['OurNetScore'] > $row['OppNetScore']) echo "<td align=\"center\" bgcolor=\"#04B404\">" . "defeated"; else echo "<td align=\"center\" bgcolor=\"#FF0000\">" . "defeated by" . "</td>"; echo "<td align=\"center\">" . $row['Name'] . "</td>"; echo "<td class=\"grey\" align=\"center\">" . $row['OppNetScore'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "<br>"; $query="SELECT COUNT(*) AS TotWins FROM Fixtures WHERE WinLossDraw = 'W' AND Season = 1"; $result = mysql_query($query) or die(mysql_error()); echo "<table align=\"center\">"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class=\"green\" align=\"center\">" . "Won : " . $row['TotWins'] . "</td>"; echo "</tr>"; } echo "</table>"; $query="SELECT COUNT(*) AS TotLoss FROM Fixtures WHERE WinLossDraw = 'L' AND Season = 1"; $result = mysql_query($query) or die(mysql_error()); echo "<table align=\"center\">"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class=\"red\" align=\"center\">" . "Lost : " . $row['TotLoss'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> </body> </head> </html> Link to comment https://forums.phpfreaks.com/topic/154315-refresh-page-after-drop-down-box-selection/ Share on other sites More sharing options...
Mchl Posted April 16, 2009 Share Posted April 16, 2009 You will need some AJAX for that. Link to comment https://forums.phpfreaks.com/topic/154315-refresh-page-after-drop-down-box-selection/#findComment-811264 Share on other sites More sharing options...
woolade Posted April 21, 2009 Author Share Posted April 21, 2009 I've still been searching for an answer to this and just cannot seem to find it. Is there anyone who can help me with this or point me in the right direction as to where I can start to try and work this out. If easier I could just have the selection redirect to another page based on that selection. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/154315-refresh-page-after-drop-down-box-selection/#findComment-815122 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.