Help with multiple arguments

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
khanfahd
Forum Newbie
Posts: 1
Joined: Sun Nov 10, 2002 5:18 am

Help with multiple arguments

Post by khanfahd »

i made a dynamic form which creates a table on runtime, and in front of every record shows a checkbox.

following is code:

Code: Select all

while($xyz=mysql_fetch_array($sql_select))
	{
		$cat_id=$xyzї"cat_id"];
		$cat_name=$xyzї"cat_name"];
		$cat_desc=$xyzї"cat_desc"];
		
		print("<tr>");
		print("<td><input type=checkbox name=c1 value=$cat_id></td>");
		print("<td>$cat_id</td>");
		print("<td>$cat_name</td>");
		print("<td>$cat_desc</td>");
		print("</tr>");
	&#125;
the problem with this is that, when i select multiple checkboxes, it still sends only a single value.
Can someone please help me with this
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post by PaTTeR »

You need to change checkbox name on every loop

Code: Select all

$count=1;
while($xyz=mysql_fetch_array($sql_select)) 
   &#123; 
      $cat_id=$xyz&#1111;"cat_id"]; 
      $cat_name=$xyz&#1111;"cat_name"]; 
      $cat_desc=$xyz&#1111;"cat_desc"]; 
       
      print("<tr>"); 
      print("<td><input type=checkbox name=c$count value=$cat_id></td>"); 
      print("<td>$cat_id</td>"); 
      print("<td>$cat_name</td>"); 
      print("<td>$cat_desc</td>"); 
      print("</tr>"); 
      $count++;	
   &#125;
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

check boxes and arrays

Post by phpScott »

If you want to keep track of whick checkboxes people of selected in that group then name them like so:

<input type="checkbox" name="cb[]" value="first selection">
<input type="checkbox" name="cb[]" value="another selection">

will create and array called cb[] that you can now run through and see what values have been passed along with each selection.

save all that seperate name stuff and having to deal with too many variable names.

phpScott
Post Reply