0

hi all,
it's my code ,i want to display check box and two drop down list in a table ,
user can choose which one check box and set some value from drop down list ,
then i want send the row that user selected and these settings values from drop down list, but it's will send all rows drop down list value (not only check box checked)
any one knows how to modify ?

<?
        $sql="select id , name, email from user ;";
        $result = mysql_query($sql);
        if (!$result) {
                die("Query to show fields from table failed");
        }
        $result_num = mysql_num_rows($result);        
        echo "<form name=\"myForm\" action=\"recv.php\" method=\"POST\">
                <table border=1>
                   <tr bgcolor=#C0C0C0>
                <td><center></center></td>
                      <td><center>Name</center></td>
                <td><center>email</center></td>
                    <td><center>type</center></td>
                                <td><center>price</center></td>
                </tr>        ";
        
        if ($result_num==0){
            $this->error = $sql;
            return false;
        }else{
            for ($i=0;$i<$result_num;$i++){
            
                echo "<tr>";
                $row = mysql_fetch_array($result);
                $uid = $row['id '];
                $name = $row['name'];
                $email = $row['email '];
                $ type = ' type_'.$uid;
                 $ckd = 'ckd_'.$i;
                $price= 'price_'.$uid;
                if($i==0) echo "<input type=\"checkbox\" name =\"$ckd\" id=\"$ckd\" value=\"$uid\" Checked onClick=\"chooseOne(this);\">";
                    else echo "<input type=\"checkbox\" name =\"$ckd\" id=\"$ckd\" value=\"$uid\" onClick=\"chooseOne(this);\">";
                
                echo "<td>$name</td>";
                echo "<td>$email</td>";
                echo "<td><select name=\"$ type \" >
                    <option value=\"1\">modelA </option>
                    <option value=\"2\">modelA </option>
                    </select></td>";
                
                echo "<td><select name=\"$price\" >
                <option value='1' >low</option>
                <option value='2'>high</option>
        
                </select></td>";
                
                
                echo "</tr>\n";
                

            }
            <input value=\"Test\" type=\"submit\" onclick=\"this.disabled=true ; \" >
        
            echo "</table>";
            echo "</form>";
            
        
        }
?>

html result img :
http://img256.imageshack.us/img256/474/nonamesq.jpg

Edited by stefansaye: add img

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by sudeepjd
0

When you use a HTML form, all the input elements will be sent. What you can do is to pick out the ones you want. You can do this by naming the checkbox as an array echo "<input type=\"checkbox\" name =\"check[]\" id=\"check[]\" value=\"$uid\" Checked onClick=\"chooseOne(this);\">"; This would pull the values into an array. Loop through the array with a foreach loop. Take the uid, attach it to the price and type to get the variables of the dropdown lists from which you want to pull the data.

$check=$_POST['check'];
if (sizeof($check)>0){
	foreach($check as $chk_id){
	      $ckh_box[]=$chk_id	
              $title[]=$title['title_'.$chk_id];
              $price[]=$price['price_'.$chk_id]; 
	}
}

I have not tested out the code. Just wrote it on the fly, this is the jist of what you should be able to use. This would pull the required data to the respective arrays which you can use later.

Let me know if this does not work for you.

This topic has been dead for over six months. 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.