kernelgpf Posted May 16, 2007 Share Posted May 16, 2007 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 https://forums.phpfreaks.com/topic/51754-radio-buttons/ Share on other sites More sharing options...
boo_lolly Posted May 16, 2007 Share Posted May 16, 2007 the 'name' of each radio button input field should not be $row['itemid']. it should look like this: <INPUT type="radio" value="{$row['itemid']}" name="delMsg[]"> and what are all the hidden input fields for? Link to comment https://forums.phpfreaks.com/topic/51754-radio-buttons/#findComment-254940 Share on other sites More sharing options...
kernelgpf Posted May 17, 2007 Author Share Posted May 17, 2007 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 https://forums.phpfreaks.com/topic/51754-radio-buttons/#findComment-254944 Share on other sites More sharing options...
hitman6003 Posted May 17, 2007 Share Posted May 17, 2007 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 https://forums.phpfreaks.com/topic/51754-radio-buttons/#findComment-254945 Share on other sites More sharing options...
kernelgpf Posted May 17, 2007 Author Share Posted May 17, 2007 I tried your $sign array code, hitman, and for some reason $sign[0] keeps coming out "z-1", when I have a "-1". Why is that? Link to comment https://forums.phpfreaks.com/topic/51754-radio-buttons/#findComment-255536 Share on other sites More sharing options...
hitman6003 Posted May 17, 2007 Share Posted May 17, 2007 what $sign? You must be concatenating a "z" with our variable at some point. Can you post your code? Link to comment https://forums.phpfreaks.com/topic/51754-radio-buttons/#findComment-255614 Share on other sites More sharing options...
kernelgpf Posted May 17, 2007 Author Share Posted May 17, 2007 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 https://forums.phpfreaks.com/topic/51754-radio-buttons/#findComment-255929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.