Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Passing dropdown list value to another SELECT statement on same page

MySQL Select Dropdown

12:30 pm on Aug 1, 2012 (gmt 0)

New User

5+ Year Member

joined:Aug 1, 2012
posts: 1
votes: 0

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 my code so far:


// 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>";
if ($nt[racename]==$_POST["racename"])
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

[edited by: coopster at 9:04 pm (utc) on Jan 20, 2013]
[edit reason] removed personal url [/edit]

9:07 pm on Jan 20, 2013 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 2

Hello GameHermit and a belated welcome to WebmasterWorld.

Your link didn't offer much in the way of direction and we tend to ask folks to explain the issue rather than link to a page. Written issues will remain in this forum indefinitely whereas personal page links change or go 404 more often than not, which render future readers helpless to fully understand the problem.

First, are you getting errors when you attempt to build the select list? You can find out by looking at your php error log.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members