Jump to content

form actions with PHP


vidyashankara

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?
Link to comment
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.
Link to comment
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]
Link to comment
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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.