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
https://forums.phpfreaks.com/topic/54463-solved-array-issues-post/
Share on other sites

Robyn...I made a script like this for a website the other day, here is my post on it.

http://www.phpfreaks.com/forums/index.php/topic,143185.msg611475.html#msg611475

 

That will probably help you a lot. I just couldn't figure out a good way to put it into the array. Look at Frosts post.

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

Archived

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

×
×
  • 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.