Jump to content

Archived

This topic is now archived and is closed to further replies.

vidyashankara

form actions with PHP

Recommended Posts

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,
[code]
<input type=checkbox name=chain value=a>
<input type=checkbox name=chain value=b>
<input type=checkbox name=chain value=c>
[/code]

If $chain =4 then,
[code]
<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>
[/code]

how do i do that?

Share this post


Link to post
Share on other sites
This will do:

[code]<?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";
}

?>[/code]

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

Share this post


Link to post
Share on other sites
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.

[code]
$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>";
}
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=381516:date=Jun 8 2006, 02:17 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 8 2006, 02:17 PM) [snapback]381516[/snapback][/div][div class=\'quotemain\'][!--quotec--]
This will do:

[code]<?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";
}

?>[/code]

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!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.