Jump to content

mysql_fetch_array stored in POST array


rbragg

Recommended Posts

Hopefully, this will be a quick and painless answer. The values for the the last playerID in the db table are the only values passed in the POST array. I would like to have values for all 17 playerIDs passed and not just the 17th. Thanks in advance.

 

<?php
$queryPlayers = "
SELECT playerID, player 
FROM players
$playerResults = mysql_query($queryPlayers) or die('Find players query failed: ' . mysql_error()); 

while ($player = mysql_fetch_array($playerResults))
{ 
echo "<input name='playerID' type='hidden' value='" . $player['playerID'] . "'";
echo "<tr>";
?>
<td align='center'><input name="hits" type="text" size="3" maxlength="3" value="0" class="style3" /></td>
<td align='center'><input name="ab" type="text" size="3" maxlength="3" value="0" class="style3" /></td>
<td align='center'><input name="bb" type="text" size="3" maxlength="3" value="0" class="style3" /></td>
<td align='center'><input name="2b" type="text" size="3" maxlength="3" value="0" class="style3" /></td>
<td align='center'><input name="3b" type="text" size="3" maxlength="3" value="0" class="style3" /></td>
<td align='center'><input name="hr" type="text" size="3" maxlength="3" value="0" class="style3" /></td>
<td align='center'><input name="rbi" type="text" size="3" maxlength="3" value="0" class="style3" /></td>
</tr>
<?php		
}
?>

Link to comment
https://forums.phpfreaks.com/topic/49832-mysql_fetch_array-stored-in-post-array/
Share on other sites

I'm pretty sure you can't pass an array in the POSTarray, but you might be able to do something, do the query to get the information, then do a foreach or while loop and echo a new hidden input field, with the name of something like:

 

<input type="hidden" name="playerID[]" value="$row['playerID']" />

 

I don't really know since I've never tried this, but it could work.  Look on php.net and google, they might help.

 

edit: D'oh, beat to it.  Well, there you go.

akitchin, it's getting there! I named all of the inputs as arrays, ie. hits[]. Now my information is stored within the POST array for each input.

 

The problem I have now is that the playerID is not associating itself with the input. Instead of having say (for playerID# 5):

 

[hits] => Array ([5] => 3

 

I have:

 

[hits] => Array ([0] => 3

 

It increments from 0 to 16. I know I must associate the playerID somehow with each input but I'm not sure how to go about that. I'm sure there is some trick.

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.