MySQL Forums
Forum List  »  PHP

Passing dropdown list value to another SELECT statement on same page
Posted by: Jack Berberette
Date: August 01, 2012 07:20AM

Hi and thanks for looking at this with me. I am COMPLETELY new to using PHP to run MySQL select statements. That being said, I have managed to run a SELECT statement to populate a drop down list...and another SELECT statement to populate an HTML table. (this is for a roleplaying game)

But this is where3 I get stuck...

I would like for the dropdown selected value to be the "WHERE racename = " value in the second select statement that populates the table so that only one row is returned instead of all the data.

Here's the page: [gamehermit.com...]

Here's my code so far:


<?php

// Make a MySQL Connection

mysql_connect("localhost", "db_username", "password") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());

$query="SELECT * FROM Races";
$result = mysql_query($query);
echo "<select name=racename>";
while($nt=mysql_fetch_array($result))
{
if ($nt[racename]==$_POST["racename"])
$selected="selected";
else
$selected="";
echo "<option ".$selected."value=$nt[racename]>$nt[racename]</option>";
}
echo "</select>";
echo "<br />";

// Get all the data from the "Race" table and create table

$result2 = mysql_query("SELECT * FROM Races")
or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>Race Name</th> <th>Might Modifier</th> <th>Valor Modifier</th> <th>Deftness

Modifier</th> <th>Insight Modifier</th> <th>Dweomer Modifier</th> </tr>";

// keeps getting the next row until there are no more to get

while($row = mysql_fetch_array( $result2 )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['racename'];
echo "</td><td>";
echo $row['modmight'];
echo "</td><td>";
echo $row['modvalor'];
echo "</td><td>";
echo $row['moddeftness'];
echo "</td><td>";
echo $row['modinsight'];
echo "</td><td>";
echo $row['moddweomer'];
echo "</td></tr>";
}
echo "</table>";

?>


I hope this is simple...thanks so much :)

~ Jack

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.