Checkbox problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anser316
Forum Newbie
Posts: 4
Joined: Sat Apr 12, 2008 7:31 pm

Checkbox problem

Post by anser316 »

Hi I havent solved this checkbox problem for ages, so i would really appreciate if i could get some help.

From a table on mysql, i have listed specific rows. There are two PK's, (DRUG_ID,BRANCH_ID)
I want to select certain rows, and display them on another form.
e.g.
DID BID STOCK
1 1 3
1 2 4
2 1 6
2 2 5

I have tried a few different ways and none have worked. This is what i currently have

Form 1

Code: Select all

$result2 =mysql_query("SELECT ....");
echo "<form action= conorder.php method=POST>";
  echo "<table border='1'>";
   echo "<tr> <th>DRUG ID</th> <th>Branch ID</th><th>STOCK</th></tr>";
   $counter=0;
   while($row = mysql_fetch_array( $result2 )) {
   echo "<tr><td>";
   echo "<input type='hidden' name=drug_id[$counter] value='$row[drug_id]'>";
   echo $row['drug_id'];
   echo "</td><td>";
   echo "<input type='hidden' name=branch_id[$counter] value='$row[branch_id]'>";
   echo $row['branch_id'];
   echo "</td><td>";
   echo "<input type='hidden' name=total_stock[$counter] value='$row[total_stock]'>";
   echo $row['total_stock'];
   echo "</td><td>";
   echo "<input type=checkbox name=ticked[] value='$counter'>";
   echo "</td></tr>"; 
   $counter++;
   }
  echo "</table>";
 echo "<input type =submit value= Submit>";
 echo "<input type = reset>";
echo "</form>";
Form 2

Code: Select all

if (isset($_POST['ticked'])) {
  for ($i=0; $i<count($_POST['ticked']); $i++) {
   echo "<br>drug id: ";
   echo $_POST[drug_id][$i];
   echo "    branch id: ";
   echo $_POST[branch_id][$i];
   echo "    stock: ";
   echo $_POST[total_stock][$i];}
}
The problem I am getting is as follows:
If for example i select rows 2 and 3, I get rows 1 and 2.
Or if i select row 4, i get row 1.

Where have i gone wrong?
anser316
Forum Newbie
Posts: 4
Joined: Sat Apr 12, 2008 7:31 pm

Re: Checkbox problem

Post by anser316 »

SOLVED.
Post Reply