NackelShipley Posted December 4, 2009 Share Posted December 4, 2009 Ok so I own an online RPG, and yes it's Pokemon. A little immature I know, but I've owned the site for close to 10 years now, so when I started it, Pokemon was very much in fashion for my age group and now the site has grown so much I can't let it go. Anyways I have a problem with a page of mine, so I'll describe the problem as best as I can, any help is appreciated thank you in advance. So I have a field on my form which looks like this: <input type='text' name='Price[]' value='$suggested'></input> Now how do I get that to give me the input value for each value relative to that part of the form? I mean I'm listing the items to be sold, with two text input fields for each item 'Price' and 'Private' along with a checkbox that determines the 'ID' of the selected item, well the ID and checkboxes work it outputs the item name of each item checked in order. I just can't get it to give me the inputed price for each selected item. I hope you understand, if you need it, the whole code for the page is below. <center><font face='verdana' size='2'><b>Sell Unwanted Pokemon</b></font><br><br><font face='verdana' size='1'>You can sell Pokemon that you no longer want, to sell a Pokemon first check the box under the image of that Pokemon, then you must fill in a price you want to sell the Pokemon for, and determine if the sale will be 'private' or to the general trainer population. The suggested price is a price determined by that Pokemon's rarity and other factors, it does not mean you have to sell a Pokemon for that price.<br><br> <?php if(isset($_POST['Submit']) && isset($_POST['Sell'])) { $Sell = $_POST['Sell']; print "<font face='verdana' size='2' color='Green'><b>The selected Pokemon have been sold!</font></b><br><br>"; $result = mysql_query("SELECT * FROM t_pokemon where Trainer!=''"); $num_rows = mysql_num_rows($result); $D = 0; $P = 0; $getall="SELECT * FROM `t_pokemon` where Trainer='$getuser3[username]' ORDER BY `ID` ASC"; $getall2=mysql_query($getall) or die("Could not get PokeMail data."); while($getall3=mysql_fetch_array($getall2)) { if($D <= $num_rows) { $getsold="SELECT * from t_pokemon where ID='$Sell[$D]' AND Trainer='$getuser3[username]'"; $getsold2=mysql_query($getsold) or die("Could not get user info"); $getsold3=mysql_fetch_array($getsold2); $Price = $_POST['Price[$P]']; print "$getsold3[Pokemon] - $Price"; $P = $P+1; $D = $D+1; } } } print "<div style='width: 100%; height: 700px; overflow: auto; border-top:1px solid black; border-bottom:1px solid black'><form name='Sell' action='index.php?function=Sell' method='POST'><table width='100%' cellspacing='0' cellpadding='2'><tr>"; $b = 0; $r = 0; $P = 0; @$getbox="SELECT * FROM `t_pokemon` WHERE `Trainer`='$getuser3[username]' AND ID!='$getselected3[iD]' AND `Pokemon` LIKE CONVERT(_utf8 '$Box%' USING latin1) COLLATE latin1_swedish_ci order by Pokemon ASC"; @$getbox2=mysql_query($getbox) or die("Could not get box Pokemon."); while($getbox3=mysql_fetch_array($getbox2)) { if($getuser3[starter] != $getbox3[iD] && $getuser3[second] != $getbox3[iD] && $getuser3[Third] != $getbox3[iD] && $getuser3[Third] != $getbox3[iD] && $getuser3[Fourth] != $getbox3[iD] && $getuser3[Fifth] != $getbox3[iD] && $getuser3[sixth] != $getbox3[iD]) { $poke1 = "SELECT COUNT(*) AS usercount FROM t_pokemon where Pokemon='$getbox3[Pokemon]'"; $poke2=mysql_query($poke1) or die(mysql_error()); $pokecount= mysql_result($poke2, 0); $suggested= ROUND(($getbox3[Level]*$getbox3[MHP]*100)/($pokecount/10)); print "<td style='"; if($b > 0) { print "background: #FFFFF0;"; } print " border-bottom:1px solid black; border-right:1px solid black'><font face='verdana' size='1'><center><b>$getbox3[Pokemon]</b>"; $female = '♀'; $male = '♂'; if($getbox3[Gender] == 'Male') {print "$male";} if($getbox3[Gender] == 'Female') {print "$female";} print "<i> $getbox3[shiny]</i><br><img src='images/pokemon/small/$getbox3[Pokemon].png'><br><b>Level:</b> $getbox3[Level]<br><br><b>Selling Price</b><br><i>Without commas.<br></i>$<input type='text' name='Price[]' size='20' style='border:1px solid black; font: verdana; font-size: 10px;' maxlength='12' value='$suggested'></input><br>Max $999,999,999,999.<br><br><b>Private Sale</b><br><i>Leave blank if global sale.</i><br><input type='text' name='privatesale' size='20' style='border:1px solid black; font: verdana; font-size: 10px;' maxlength='20'></input><br><br><b>Sell $getbox3[Pokemon]?</b> <input type='Checkbox' name='Sell[]' value='$getbox3[iD]'></input><br></td>"; $P = $P+1; $r = $r+1; if($r == '3') { print "</tr><tr>"; $r = 0; } $b = $b+1; if($b == '2') { $b = 0; } } } print "</table></div>"; if($getuser3[username] == 'NackelShipley') { print "<br><br><input type='Submit' name='Submit' value='Sell Pokemon!' style='border:1px solid black; font: verdana; font-size: 10px'></input>"; } print "</form>"; print "<br><br>"; ?> My coding is a little primative and messy I know. Thanks again for any help. EDIT: I accidentaly made an obvious mistake in the code so I changed it to what it is now. Quote Link to comment https://forums.phpfreaks.com/topic/184009-array-help/ Share on other sites More sharing options...
mikesta707 Posted December 4, 2009 Share Posted December 4, 2009 when you pass an HTML array like that, the returned value in the post array is an array itself. so $Price = $_POST['Price[$P]']; is actually incorrect, it should be $Price = $_POST['Price']; and you could then loop through that array by doing something like foreach($Price as $eachPrice){ //whatever or one of PHP's other looping functions in your case, since you seem to already have a counter variable ($P) you may be able to just do $Price = $_POST['Price;'][$P]; and that would get you the price at offset $P Quote Link to comment https://forums.phpfreaks.com/topic/184009-array-help/#findComment-971474 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.