PHP-General - Issues with getting value of currently selected option in a dropdown
Discuss Issues with getting value of currently selected option in a dropdown in the PHP Development forum on Dev Shed. Issues with getting value of currently selected option in a dropdown PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 4
Time spent in forums: 31 m 57 sec
Reputation Power: 0
PHP-General - Issues with getting value of currently selected option in a dropdown
Ok So I have 2 tables, one with Assignment names (Homework1, Homework2, etc) and a table with Student grades for each assignment (So mary might have entries for HW1, HW2 and Joe would also have entries for HW1 and HW2)
Currently I'm using php to grab the list of homeworks from the first table and shove them into a dropdown, no problem there.
But what I want to do is then grab that selected dropdown value, and use it in an SQL query to narrow grade results to JUST the selected Assignment
PHP Code:
<?
$HWname = "SELECT hwname FROM Homeworks ORDER BY hwname ASC";
$HWnameResult = mysql_query($HWname) or die(mysql_error());
$table = "SELECT Student,NumCorrect,NumTotal,Score FROM StudentGrades WHERE Class='{$_POST[hwname]}' ORDER BY Student ASC";
$tableResult = mysql_query($table) or die(mysql_error());
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones
09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. -- Jamie Zawinski
Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ... BIT COINS ANYONE
Posts: 9,811
Time spent in forums: 2 Months 3 Weeks 19 h 13 m 52 sec
Reputation Power: 6112
Is there more to this application? For instance, is there a properly-formed <form> tag and a properly formed <input type="submit"> button? If you have those, does the form's action have code which retrieves the value of your drop-down and draws the appropriate page?
Your "issue" seems to be that you're not done writing this application.
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Posts: 4
Time spent in forums: 31 m 57 sec
Reputation Power: 0
Here's my updated code, I added a button to submit, and I use the SQL query that grabs the HW name as the action.
PHP Code:
<?
$HWname = "SELECT hwname FROM Homeworks ORDER BY hwname ASC";
$HWnameResult = mysql_query($HWname) or die(mysql_error());
$table = "SELECT Student,NumCorrect,NumTotal,Score FROM StudentGrades WHERE Class=???? ORDER BY Student ASC";
?>
My issue right now is in the $table variable, I don't know what to put after Class= so that it grabs the submitted value of the dropdown box and uses it in the query
Posts: 4
Time spent in forums: 31 m 57 sec
Reputation Power: 0
I did the "echo $_POST['Homeworks']; " to make sure that it's grabbing info correctly and it is. If I select Homework1 and hit Check, "Homework1" pops up on the page and vice versa for anything else I select. I just can't figure out how to take that text and throw it into the second query
Posts: 9,811
Time spent in forums: 2 Months 3 Weeks 19 h 13 m 52 sec
Reputation Power: 6112
PHP Code:
$table = "SELECT Student,NumCorrect,NumTotal,Score FROM StudentGrades WHERE Class='" . mysql_real_escape_string($_POST['Homeworks']) . "' ORDER BY Student ASC";