I recently hit a little snag...maybe someone here can advise me on the best way to accomplish this:
A little background...
So far my program generates a table and two drop down menus (ddm) containing values acquired from a mySQL database.
In order to maintain .html extension on my webpage I load this (.php) file in an <iframe>.
What I would like to happen...
1 - Everytime the user changes the value in the drop down menu that value is passed (variable) to the query that generates the table.
2 - the table should automatically refresh. In the same window. (not sure if I should have the table in a separate <iframe>)
My main issue right now is I can't seem to get the variables to pass from the function when a selection is made.
here is some of the code to give you an idea:
Any suggestions would be greatly appreciated.
Thanks,
Aaron
A little background...
So far my program generates a table and two drop down menus (ddm) containing values acquired from a mySQL database.
In order to maintain .html extension on my webpage I load this (.php) file in an <iframe>.
What I would like to happen...
1 - Everytime the user changes the value in the drop down menu that value is passed (variable) to the query that generates the table.
2 - the table should automatically refresh. In the same window. (not sure if I should have the table in a separate <iframe>)
My main issue right now is I can't seem to get the variables to pass from the function when a selection is made.
here is some of the code to give you an idea:
Code:
error_reporting(E_ALL);
//These variables will determine the search parameters
$year = $_POST['year'];
$genre = $_POST['genre'];
include 'db_connect.php';
ddm_genre();
ddm_year();
//not sure if I should make this a function as well it may be easier to pass the varible
//after the connection is made use the INSERT command to enter the values in the db
//$sql_select = "SELECT ID, Genre, Title, Director, Year FROM movies";
$sql_select = "SELECT Genre, Title, Director, Year FROM movies ORDER BY Genre";
//result set
$rs = mysql_query($sql_select);
//creating the table /w headers
echo "<html><body>";
echo "<table border='1' cellspacing='0'><tr><td>Genre</td><td>Title</td><td>Director</td><td>Year</td></tr>";
//row for each record
while ($row = mysql_fetch_array($rs)) {
echo "<tr><td>" . $row['Genre'] . "</td><td>" . $row['Title'] . "</td><td>" . $row['Director'] . "</td><td>" . $row['Year'] . "</td></tr>";
}
echo "</table>";
echo "</body></html>";
//free memory
mysql_free_result($rs);
//close the db
mysql_close();
//functions
function ddm_genre(){
//query to SELECT the dd-menu option values
$select = "SELECT DISTINCT Genre FROM movies ORDER BY Genre";
//Result Set
$rs_genre = mysql_query($select) or die(mysql_error());
//If no rows are returned display default error message
if (!mysql_num_rows($rs_genre)) {
die(mysql_error());
}
//Else make drop down box
else {
echo "<form name='genre' action='db_select.php' method='post'>";
echo "<label>Genre: ";
echo "<select name='genre' id='genre'>";
//Each row in the rs will be an option
while ($row = mysql_fetch_array($rs_genre))
{
echo "<option value='".$row['Genre']."'>".$row['Genre']."</option>";
}
}
echo "</label>";
echo "</select>";
echo "</form>";
//free memory
mysql_free_result($rs_genre);
}
function ddm_year(){
//query to SELECT the dd-menu option values
$select = "SELECT DISTINCT Year FROM movies ORDER BY Year";
//Result Set
$rs_year = mysql_query($select) or die(mysql_error());
//If no rows are returned display default error message
if (!mysql_num_rows($rs_year)) {
die(mysql_error());
}
//Else make drop down box
else {
echo "<form name='year' action='db_select.php' method='post'>";
echo "<label>Year: ";
echo "<select name='year' id='year'>";
//Each row in the rs will be an option
while ($row = mysql_fetch_array($rs_year))
{
echo "<option value='".$row['Year']."'>".$row['Year']."</option>";
}
}
echo "</label>";
echo "</select>";
//free memory
mysql_free_result($rs_year);
}
Any suggestions would be greatly appreciated.
Thanks,
Aaron