2

i having two check boxes when i am selecting both check boxes i want to show the value related to both from database ,but now i able to print only one id of check boxes i want to show both data can anyone help hoe to show both a value ,Below is my code:

html

 <input type="submit" name="Update" src="/image/exporttt.png" style="margin:0px;cursor:pointer">

<tbody>
<?php

$clientid=$_GET['clientid'];

if($clientid!=""){

$sql = mysql_query("SELECT * FROM clientnetworkpricehistory");


while($rows=mysql_fetch_array($sql))
{
if($alt == 1)
        {
           echo '<tr class="alt">';
           $alt = 0;
        }
        else
        {
           echo '<tr>';
           $alt = 1;
        }

echo ' 
        <td id="CPH_GridView1_clientid" style="width:140px" class=" clientid '.$rows["net_id"].'">'.$rows["clientid"].'</td>
        <td id="CPH_GridView1_country" style="width:160px" class=" country '.$rows['net_id'].'">'.$rows["country"].'</td>       
        <td id="CPH_GridView1_networkname" style="width:156px" class="networkname '.$rows["net_id"].'">'.$rows["networkname"].'</td>
        <td id="CPH_GridView1_mccmnc" style="width:250px" class=" mcc'.$rows["net_id"].'">'.$rows["mcc"].'</td> 
        <td id="CPH_GridView1_mccmnc" style="width:250px" class=" mnc '.$rows["net_id"].'">'.$rows["mnc"].'</td>         
        <td id="CPH_GridView1_oldprice" style="width:320px" class=" oldprice '.$rows["net_id"].'">'.$rows["pricefrom"].'</td>
        <td id="CPH_GridView1_newprice" style="width:129px" class=" newprice '.$rows["net_id"].'">'.$rows["priceto"].'</td> 
        <td id="CPH_GridView1_oldroute" style="width:143px" class="oldsupplierroute '.$rows["net_id"].'">'.$rows["routefrom"].'</td>    
        <td id="CPH_GridView1_newroute" style="width:143px" class=" newsupplierroute '.$rows["net_id"].'">'.$rows["routeto"].'</td>     
        <td id="CPH_GridView1_comments" style="width:143px" class=" comments '.$rows["net_id"].'">'.$rows["status"].'</td>      
        <td id="CPH_GridView1_from" style="width:143px" class=" fromdate '.$rows["net_id"].'">'.date('d.m.Y H:i', $rows["datetime"]).'</td>         

        <td style="width:65px" class=" '.$rows["net_id"].'"><input type="checkbox" name="chk1" value=" '.$rows["net_id"].'"/></td>

        </tr>';
}
}
?>

</tbody>

jssearch.php

<?php
 //connecting to db     
$variable=$_POST['chk1'];
foreach ($variable as $variablename)
{
$sql_select="SELECT * from clientnetworkpricehistory where net_id=$variablename";
$queryRes = mysql_query($sql_select);
print"$sql_select";
}
echo "<table border='1'>
<tr>
<th>country</th>
<th>networkname </th>
<th>mcc</th>
<th>mnc</th> 
        <th>datetime </th>
</tr>";

while($row = mysql_fetch_array($queryRes))
{
echo "<tr>";
echo "<td>" . $row['country'] . "</td>";
echo "<td>" . $row['networkname'] . "</td>";
echo "<td>" . $row['mcc'] . "</td>";
echo "<td>" . $row['mnc'] . "</td>"; 
echo "<td>" . $row['datetime'] . "</td>"; 
echo "</tr>";
}
echo "</table>";
?> 

my out put was(i am checked two checkboxes and i am trying to print two check boxes id it only showing one can any one help me how to do that)

56
Warning: Invalid argument supplied for foreach()

2 Answers 2

4

Use name="chk1[]" in your HTML so the checkboxes will be posted as an array.

Besides that:

  1. The mysql_* functions are deprecated, consider using mysqli_* or PDO
  2. You are vulnarable to SQL-injection on your where net_id=$variablename"
Sign up to request clarification or add additional context in comments.

Comments

2

I agree with Peter but you also might wanna fix this little typo:

'.$rows['net_id'].'">'.$rows["country"].'

That's line 2 of that large echo you have with all the <td>s. The $rows['net_id'] should be double quotes.

But you knew that...:)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.