Jump to content

Refresh Page after drop down box selection


woolade

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.