Jump to content

Running a mysql query from drop down box selection


TheChaosFactor

Recommended Posts

Ok, so the title is pretty straight forward, but what I'm trying to do here is have a drop down box with guild members name it in.  This box is dynamically filled using a mysql database.  Once something is selected  and the person clicks 'submit', I want it to go to a new page, transfer the selection using the $_Post(or $_Get I really don't care) method, run the correct query and then display all results in a table.  I've tried doing this several ways with no success... I even tried doing it with a text box instead and still no luck.  But this is my first ever attempt at a php application so I'm not sure what else to look for at this point.

 

The following is two of snippets of code I am attempting to use:

 

To populate the drop box(which goes fine) and to pass the value I'm using this code...

 

echo '<form action="member.php" method="get">';
echo '<select name = "memname">';
$newarray = array_unique($memname);

//Populates list box with only unique member names to avoid duplicates
for($i=0; $i <= $recordcounter; $i++){
echo '<option value ='.$newarray[$i].'>'.$newarray[$i].'</option>';
}
echo '</select>';
echo '<input type = "submit" />';
echo '</form>';

 

$memname is an array that's been used to to eliminate duplicate member names once the information is dumped from the database to populate the list box.

 

Now, to retrieve the values needed, run my query, and generate my table I'm using this code....

 

//$membername = $_Get[memname];
$query = "SELECT * FROM Aces_Donations WHERE name = '$_Get[memname]'";

//sets the results to a variable
$result = mysql_query($query) or die(mysql_error());

//opens table, sets width, color, border and headers
echo '<table bgcolor=#A85045 border = "3" width = 40%>';
echo "<tr><th alignment = 'center'>Member</th>
<th alignment = 'center'>Amount</th><th alignment = 'center'>Date</th></tr>";

while($row = mysql_fetch_array($result)){
echo "<center><tr><td alignment = 'center'>".$row['name']. "</td><td 	alignment = 'center'>". $row['amount']."</td><td alignment 	= 'center'>".$row['date']."</td></tr></center>";

echo "<br />";
}
echo '</center></table>';

 

I've also tried it with the post method. I've tried using a textbox instead of a list box, and done that with both the post and get methods.  I also tried setting the value to a variable(Which can be seen as being commented out in the example above) and using that variable in the query.  None of these seem to work.  Can anybody shoot my a few variations or maybe see something wrong with what I've done?  I've been on this for over a day now, so any help would be greatly appreciated.

 

If you would like to see exactly how it (fails to) respond, you can go to www.royalfamilyhosting.com/display.php

 

The table there uses the same while loop to generate and works fine.  There is currently a textbox instead of list box at the bottom of the page for testing, and when member.php comes up I can see the proper value passed in the URL, but still i get an empty table and I'd still perfer to use a list box to avoid user error etc.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.