0

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>
2
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by danielagaba
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?

0

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

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.

0

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

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.

0
<div id="body-panel">

                <tbody>

                            <table id="datatables" class="display">
                <thead>
                    <tr>
                        <th>Company Name</th>
                        <th>Customer Title</th>
                        <th>Product Name</th>
                        <th>Documentation Ready</th>
                        <th>Quantity Wanted</th>
                        <th>Unit Cost($)</th>
                        <th>Total Cost($)</th>
                        <th>Request date</th>
                        <th>Free Manager</th>
                        <th>Assign Manager</th>



                    </tr>
                </thead>
                <tbody>

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


                        ?>
                        <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>
                        <?php
                    }
                    ?>
                </tbody>
            </table>


                    </tbody>

    </div>
<!--BODY PANEL PANEL END-->
    <?php
        if(isset($_POST['submit'])){
            $_SESSION['uid'] = $_POST['manager'].$arr['reqid'];
            header('location:test.php');
        }

    ?>

Edited by Dani: Formatting fixed

0

use [ code ] tags - difficult to read

Anyway:
1) You don't have any <form> tags to say where the data should be sent (action) or how (method).
2) No need for a </option> immediately after the select tag.
3) Your <select> 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
}

Edited by diafol: n/a

0

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.