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
Share on other sites

you can simply name the input containing player IDs as an array:

 

echo "<input name='playerID[]' type='hidden' value='" . $player['playerID'] . "'";

 

the resulting IDs will then be in the $_POST['playerID'] array.

Link to comment
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

you can try using the playerID as the index in each of the inputs:

 

<td align='center'><input name="hits[<?php echo $player['playerID']; ?>]" type="text" size="3" maxlength="3" value="0" class="style3" /></td>

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.