Jump to content

[SOLVED] Array issues, post?


kernelgpf

Recommended Posts

Alright- I've got this little script that will "auto" do things with items, such as you can check the option to stock, discard, trade, donate, etc. an item, but with tons of items. Now- I want to pass WHAT they want to do with the item through in an array, and print out what it is they are trying to do, but my problem is that because it's a radio box option for each item, with the name of it being the item's ID number, I have no way to determine what the $_POST variable's name will be, because it will depend upon what item they've chosen to do something with.. here's my code-

 

if($_GET['action'] == "multiple"){

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="Go!">
		</td>
	</tr>
</table>
</form>';

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

 

My main problem is that the "if($_POST['actions']) {" part of my code won't trigger. Any ideas?

 

Pre-thanks to any help.

Link to comment
Share on other sites

There are two things, but I'm not totally sure about the second one.

1) Why have if($_POST['actions'] right before a foreach($_POST['actions']? This is extremely redundant - remove the if statement and if  $_POST['actions'] is not set, then it will never enter the loop.

 

2) Are you defining a two dimensional array with value="actions[stock][' . $row['itemid'] . ']"? I don't think you can define two dimensional arrays with HTML, just one dimensional. So maybe try removing [' . $row['itemid'] . '] from value and see if that works?

 

Hope any of that helps

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.