Jump to content


Photo

form actions with PHP


  • Please log in to reply
3 replies to this topic

#1 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 08 June 2006 - 06:13 PM

I have a variable $chain.

Lets say the value of $chain is 3. I want 3 checkboxes to show up with different values.

If $chain =3 then,
<input type=checkbox name=chain value=a>
<input type=checkbox name=chain value=b>
<input type=checkbox name=chain value=c>

If $chain =4 then,
<input type=checkbox name=chain value=a>
<input type=checkbox name=chain value=b>
<input type=checkbox name=chain value=c>
<input type=checkbox name=chain value=d>

how do i do that?

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 08 June 2006 - 06:17 PM

This will do:

<?php

$alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
 
$chain = 4;

for ($i=0; $i<$chain; $i++) {
   echo '<input type="checkbox" name="chain[]" value="' . $alpha[$i] . '">' . "\n";
}

?>

Obviously this limits $chain to 26, so I would rather use numbers.
~ D Kuang

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 June 2006 - 06:25 PM

i assume that, like everybody else who posts about this, you have a list of stuff in a database and you want to list the stuff with a checkbox next to each one.

$sql = "select * from table";
$rs = mysql_query($sql);
while ($list = mysql_fetch_array($rs)) {
   echo "<input type='checkbox' name='blah[]' value='" . $list['value'] . "'>" . $list['whatever'] . "<br>";
}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 08 June 2006 - 07:26 PM

[!--quoteo(post=381516:date=Jun 8 2006, 02:17 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 8 2006, 02:17 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
This will do:

<?php

$alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
 
$chain = 4;

for ($i=0; $i<$chain; $i++) {
   echo '<input type="checkbox" name="chain[]" value="' . $alpha[$i] . '">' . "\n";
}

?>

Obviously this limits $chain to 26, so I would rather use numbers.
[/quote]

Thanks dude. For some reason it dint work at first. Then i simply put the echo line and the array line without the rest and it worked! :) Thanks a bunch!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users