PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 8th, 2012, 12:36 AM
crzybldthrwr crzybldthrwr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 crzybldthrwr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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());
            
            
//Dropdown for Assignment select 
            
$dropdown "<select name='Homeworks'";
            while(
$row mysql_fetch_assoc($HWnameResult)) 
            {
              
$dropdown .= "\r\n<option value='{$row['hwname']}'>{$row['hwname']}</option>";
            }
            
$dropdown .= "\r\n</select>";
            echo 
$dropdown;
            
?>
            
            <table id="ViewGradesTable" class="table table-bordered table-condensed table-hover">
            
            <thead class="table-head">
                <?
                
echo "
                <tr>
                <th>Student Name</th>
                <th>Correct</th>
                <th>Total</th>
                <th>Score</th>
                </tr>"
?>

            </thead>

            <?
            
//Table of Student HW grades for selected Assignment
            
while($row mysql_fetch_array($tableResult))
              {
              echo 
"<tr>";
              echo 
"<td> </td>";
              echo 
"<td> </td>";
              echo 
"<td> </td>";
              echo 
"<td> </td>";
              echo 
"</tr>";
              }
            echo 
"</table>";
        
            
mysql_close($con);
            
?>


Left the connection to the database out as it's not part of the problem

Reply With Quote
  #2  
Old November 8th, 2012, 05:49 AM
Axweildr's Avatar
Axweildr Axweildr is offline
'fie' on me, allege-dly
Click here for more information.
 
Join Date: Mar 2003
Location: in da kitchen ...
Posts: 12,874 Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)  Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 2 Weeks 1 Day 20 h 28 m 56 sec
Reputation Power: 6421
Send a message via Google Talk to Axweildr
Orkut
Code:
 $dropdown = "<select name='Homeworks'>"; 
Comments on this post
ManiacDan agrees: Good eye
__________________
--Ax
without exception, there is no rule ...
Handmade Irish Jewellery
Targeted Advertising Cookie Optout (TACO) extension for Firefox
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

Reply With Quote
  #3  
Old November 8th, 2012, 03:14 PM
crzybldthrwr crzybldthrwr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 crzybldthrwr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 57 sec
Reputation Power: 0
I saw that shortly after I posted this, fixed
still having an issue

Reply With Quote
  #4  
Old November 8th, 2012, 03:30 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,717 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 29 m 55 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
And where's the code where you try to grab the value?

Reply With Quote
  #5  
Old November 8th, 2012, 03:31 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,811 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
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.
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"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

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #6  
Old November 8th, 2012, 03:47 PM
crzybldthrwr crzybldthrwr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 crzybldthrwr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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";
            
?>
            
            <form method="post" action="<? $tableResult mysql_query($table) or die(mysql_error()); ?>">
            <?
            
echo $_POST['Homeworks'];

            
//Dropdown for Assignment select 
            
$dropdown "<select name='Homeworks' id='Homeworks'>";
            while(
$row mysql_fetch_assoc($HWnameResult)) 
            {
              
$dropdown .= "\r\n<option value='{$row['hwname']}'>{$row['hwname']}</option>";
            }
            
$dropdown .= "\r\n</select>";
            echo 
$dropdown;
            
?>
            <input type="submit" id="submitbutton" name="Go" value="Check" />
            </form>
            
            <!--Table of Student HW grades for selected Assignment-->
            <table id="ViewGradesTable" class="table table-bordered table-condensed table-hover">
            <thead class="table-head">
                <?
                
echo "
                <tr>
                <th>Student Name</th>
                <th>Correct</th>
                <th>Total</th>
                <th>Score</th>
                </tr>"
?>
            </thead>

            <?
            
while($row mysql_fetch_array($tableResult))
              {
              echo 
"<tr>";
              echo 
"<td>{$row['Student']} </td>";
              echo 
"<td>{$row['NumCorrect']} </td>";
              echo 
"<td>{$row['NumTotal']}</td>";
              echo 
"<td>{$row['Score']}</td>";
              echo 
"</tr>";
              }
            echo 
"</table>";
        
            
mysql_close($con);
            
?>


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

Reply With Quote
  #7  
Old November 8th, 2012, 03:49 PM
crzybldthrwr crzybldthrwr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 crzybldthrwr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old November 8th, 2012, 10:10 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,811 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
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"

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Issues with getting value of currently selected option in a dropdown

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap