homepage Welcome to WebmasterWorld Guest from 23.23.12.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Passing dropdown list value to another SELECT statement on same page
MySQL Select Dropdown
GameHermit



 
Msg#: 4480889 posted 12:30 pm on Aug 1, 2012 (gmt 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:


<?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

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

 

coopster

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



 
Msg#: 4480889 posted 9:07 pm on Jan 20, 2013 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved