Jump to content

Radio buttons.


kernelgpf

Recommended Posts

I have a long list of items, and beside each item, there's a radio box under several options. Players should be able to select ONE radio box for each item, and the item ID needs to be stored in the array delMsg[]. Here's my code-

 

if($_POST['delete']){

$delMessages = $_POST['delMsg'];	
$type = $_POST['type'];
$num = count($delMessages);

for($i = 0; $i < $num; $i++){
	$messageID = $delMessages[$i];


	print "player wants to $type[$i] the item $messageID | ";
}
}

$query=mysql_query("select iname,itemid from items where ownerid='$sid' and equipped='no' and usf='no' and auction='no'")or die(mysql_error());

print "<table class=tstyle5><th class=tstyle5 width=50>Item</th><th class=tstyle5 width=50>Stock?</th><th class=tstyle5 width=50>Auction?</th><th class=tstyle5 width=50>Give Away?</th><th class=tstyle5 width=50>Donate?</th><th class=tstyle5 width=50>Discard</th><form method=post action=inventory.php?action=multiple>";

while($row=mysql_fetch_array($query)){

print<<<HERE
<tr><td><b>$row[iname]</b></td><td><INPUT type='radio' value='$row[itemid]' name='$row[itemid]'><input type=hidden name='type[]' value=stock></td>


<td><INPUT type='radio' value='$row[itemid]' name='$row[itemid]'><input type=hidden name='type[]' value=auction></td>


<td><INPUT type='radio' value='$row[itemid]' name='$row[itemid]'><input type=hidden name='type[]' value=giveaway></td>


<td><INPUT type='radio' value='$row[itemid]' name='$row[itemid]'><input type=hidden name='type[]' value=donate><</td>


<td><INPUT type='radio' value='$row[itemid]' name='$row[itemid]'><input type=hidden name='type[]' value=discard><</td></tr>
HERE;
}

print<<<HERE

<tr><td><script type="text/javascript" src="http://www.shawnolson.net/scripts/public_smo_scripts.js"></script>

<input type="radio" name="checkall" onclick="checkUncheckAll(this);"/> 

<input type="submit" name="delete" value="delete"></td></tr></table>

</form>
HERE;

 

Now- this allows me to select one option for each item, but doesn't pass anything to the array delMsg[]. Originally, I had the radio box name as delMsg[], which did pass the itemID to the array, but it only allowed me to select one radio box IN ALL, when I need to be able to select one per item.

 

Any ideas?

Link to comment
Share on other sites

I tried that already- when I do that, it only allows me to select a total of ONE radio box, when it should be one PER item.

 

The hidden input fields are for what they're trying to do to the item- donate, discard, give away, stock, etc.

Link to comment
Share on other sites

You need to create a multidimensional array...look at the result of the print_r to get a good idea of what's going on.

 

<?php

if ($_POST['actions']) {
foreach ($_POST['actions'] as $key => $value) {
	print "player wants to $key the item $value<br />\n";
}
}

$query=mysql_query("select iname,itemid from items where ownerid='$sid' and equipped='no' and usf='no' and auction='no'")or die(mysql_error());

echo '
<script type="text/javascript" src="http://www.shawnolson.net/scripts/public_smo_scripts.js"></script>
<form method="post" action="inventory.php?action=multiple">
<table class="tstyle5">
	<tr>
		<th class="tstyle5" width="50">Item</th>
		<th class="tstyle5" width="50">Stock?</th>
		<th class="tstyle5" width="50">Auction?</th>
		<th class="tstyle5" width="50">Give Away?</th>
		<th class="tstyle5" width="50">Donate?</th>
		<th class="tstyle5" width="50">Discard</th>
	</tr>';

while ($row = mysql_fetch_array($query)) {
echo '
	<tr>
		<td><b>' . $row[iname] . '</b></td>
		<td><INPUT type="radio" value="actions[stock][' . $row['itemid'] . ']" name="' . $row['itemid'] . '"></td>
		<td><INPUT type="radio" value="actions[auction][' . $row['itemid'] . ']" name="' . $row['itemid'] . '"></td>
		<td><INPUT type="radio" value="actions[giveaway][' . $row['itemid'] . ']" name="' . $row['itemid'] . '"></td>
		<td><INPUT type="radio" value="actions[donate][' . $row['itemid'] . ']" name="' . $row['itemid'] . '"></td>
		<td><INPUT type="radio" value="actions[discard][' . $row['itemid'] . ']" name="' . $row['itemid'] . '"></td>
	</tr>';
}

echo '
	<tr>
		<td>
			<input type="radio" name="checkall" onclick="checkUncheckAll(this);"/> 
			<input type="submit" name="delete" value="delete">
		</td>
	</tr>
</table>
</form>';

echo '<pre>' . print_r($_POST, true) . '</pre>';
?>

Link to comment
Share on other sites

Heh, I figured it out. =P I happened to be holding a baby while typing that out, and she slammed the "z" just before the opening PHP tag, and I couldn't figure out for the life of me where there was a "Z". -laughs-

 

Thanks.

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.