having trouble getting dropdown values in table
Hi,
I have a table populated by an sql query joining various tables. in every row i have a dropdown populated by another sql query and button (which for testing sakes) echos the value of the dropdown selected.
My problem is for the first row of my table, whatever dropdown value i select, the value echo'ed when I click the button is always the first. The dropdown on the other row works fine.
<tr>
<td><?php echo $arr['company']?></td>
<td><?php echo $arr['title']?></td>
<td><?php echo $arr['prodname']?></td>
<td><?php echo $arr['proddocs']?></td>
<td><?php echo $arr['qty']?></td>
<td><?php echo $arr['prodprice']?></td>
<td><?php echo $arr['total']?></td>
<td><?php echo $arr['veridate']?></td>
<td><?php
echo "<select name=manager></option>";
while($arr2 = mysql_fetch_array($result2)){
echo "<option value='".$arr2[username]."'>$arr2[username]</option>";
}
echo "</select>";
?>
</td>
<td>
<input type="submit" name="submit" value="Assign"></td>
</tr>
danielagaba
Junior Poster in Training
71 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
I don't follow. You mention 2 dropdowns - I can only see one. What data is being sent to the page? You sent a snippet that doesn't give the whole picture. Is this part of a form or have you just placed a select and submit into a html table?
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
The table has various rows (populated by an sql request). each row has a submit button and dropdown (depending on the number of records found) that is supposed to correspond to the data on that row. the drop down on every row is populated by an sql request but my problem is when the table is displayed and i pick one value on the dropdown in row one and i echo the $_POST['drop-down-name'], it brings the value of the first item in the dropdown nomatter which value i pick.
When i do the same thing to the dropdown on the second row, it returns the value i select
danielagaba
Junior Poster in Training
71 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
I assume the problem is this:
echo "<select name=manager></option>"
Every dropdown with have the same name (manager). So the last one selected will be the one that each one shows. Assuming I've understood you properly.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
okay .... how would u advise i rectify it? i was intending for users to only click based on which table row they are interested in and the specific drop down they select on that particular row so that all that data is submitted at the same time
danielagaba
Junior Poster in Training
71 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
As you've only provided a small snippet of code, I have no idea as to what is being sent to the server and how that is being processed.
What data is being sent to the page? You sent a snippet that doesn't give the whole picture
Post the rest of your code.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Company Name
Customer Title
Product Name
Documentation Ready
Quantity Wanted
Unit Cost($)
Total Cost($)
Request date
Free Manager
Assign Manager
<?php
$sql = "SELECT prodreq.prodid,prodreq.reqid, prodreq.custid, prodreq.qty, prodreq.total, prodreq.proddocs, prodreq.verilevel, prodreq.veridate, cust.custid, cust.title, cust.company, products.prodname,
products.prodid, products.prodprice FROM prodreq, cust, products WHERE prodreq.custid = cust.custid AND prodreq.prodid = products.prodid GROUP BY prodreq.reqid";
$result = mysql_query($sql) or die(mysql_error());
while ($arr = mysql_fetch_array($result)) {
$sql2 = "SELECT users.username, users.userid FROM users WHERE users.permission = 'l2' AND users.userid NOT IN(select uid from assign) ";
$result2 = mysql_query($sql2);
?>
<?php echo $arr['company']?>
<?php echo $arr['title']?>
<?php echo $arr['prodname']?>
<?php echo $arr['proddocs']?>
<?php echo $arr['qty']?>
<?php echo $arr['prodprice']?>
<?php echo $arr['total']?>
<?php echo $arr['veridate']?>
<?php
echo "";
while($arr2 = mysql_fetch_array($result2)){
echo "$arr2[username]";
}
echo "";
?>
<?php
}
?>
<?php
if(isset($_POST['submit'])){
$_SESSION['uid'] = $_POST['manager'].$arr['reqid'];
header('location:test.php');
}
?>
danielagaba
Junior Poster in Training
71 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
use [ code ] tags - difficult to read
Anyway:
1) You don't have any tags to say where the data should be sent (action) or how (method).
2) No need for a immediately after the select tag.
3) Your tag has a name="manager" in every case. As I mentioned this is bad.
You can give your name attribute an array like this:
<select name="manager[]">
or give each a unique key baes on one of the fields from your DB:
echo "<select name=\"manager[{$arr['some_field']}]\">";
You then pick up the data in your form handling code:
$managers = (array) $_POST['manager'];
foreach($managers as $id => $value){
//do what you need
}
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Thanks for the help. finally got it. had forgotten to give each button on every row a unique id. in the end the code looked like this
<select name="manager<?php echo $arr['reqid'];?>">
<?php
while($arr2 = mysql_fetch_array($result2)){
echo "<option value='".$arr2['userid']."'>$arr2[username]</option>";
}
echo "</select>";
?>
</td>
<td>
<input type="submit" name="submit<?php echo $arr['reqid'];?>" value="Assign"></td>
danielagaba
Junior Poster in Training
71 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0