Jump to content

Loopin through records


Mr Chris

Recommended Posts

Hi,

 

I'm trying to get a value out of my database and it's value held in a dropdown:

 

So basically I wnat to loop through all the records and find the value for each cards value in the database, so I can update it if needs be

 

for($i = 0; $i < count($_REQUEST['bks']) ; $i++)
{
  $result = mysql_query("Update player_stats set cards ='".$_REQUEST['bks'][$i]."' WHERE report_id ='$x' AND stats_id=".$_REQUEST['id'][$i]) OR DIE(mysql_error());
}

 

Now, i've tried doing it, but got stuck (See below).  Can anyone help.  Thanks

 


<?php $c_id = $databaseArray['cards'] ? $databaseArray['cards'] : ''; ?>
   <select class="input" name="bks[]" id="bks" size="1"  style="width: 145" tabindex="1">
   <option value="" <?php echo ($c_id == '' ? 'selected="selected"' : ''); ?>>Bookings</option>
?>
</select>

Link to comment
Share on other sites

this doesn't make sence

 

<?php $c_id = $databaseArray['cards'] ? $databaseArray['cards'] : ''; ?>

 

if it has a value then set $c_id to it, else set $c_id to '',

 

the logic is a little mixed up.. can you explain a little more also some extra code may help

ie what is databaseArray['cards'] a list of cards or a selected card

where are you pulling from the database ?

 

the subject also doesn't help

Link to comment
Share on other sites

Thanks,

 

OK Here Goes...

 

Here's my database:

 

cards.jpg

 

The below script looks through all of my records in my database and outputs the type of card issued to each player (stats_id):

 

<?php

$databaseInfo = mysql_query("SELECT * From player_stats") or die(mysql_error());

// Update the new values in the database
if(isset($_POST['Submit']))
{

for($i = 0; $i < count($_REQUEST['bks']) ; $i++)
{
  $result = mysql_query("Update player_stats set cards ='".$_REQUEST['bks'][$i]."' WHERE stats_id=".$_REQUEST['id'][$i]) OR DIE(mysql_error());
}

} //end of post

?>
        <?php while ($databaseArray = mysql_fetch_array($databaseInfo)){ ?>
          <input name="bks[]" type="text" id="bks" value="<?php echo $databaseArray['cards']?>" size="36" />
        <?php } // end of while loop ?>
        <input type="submit" name="Submit" value="Submit" class="button">
        <input type="reset" name="Reset" value="Reset" class="button"></td>
</form>
</body>
</html>

 

And this works great, and as you can see each value in the database holds the word yellow or red or nothing.  So on this line where it outputs the data from the database

 

<input name="bks[]" type="text" id="bks" value="<?php echo $databaseArray['cards']?>" size="36" />

 

I want to change the form element to a dropdown menu rather than a input box

 

With the value in the database automatically selected ie yellow or red  or nothing (which says the words please select)

 

And then have the option to change those values for each record?

 

Hope that's clearer - can you help?

 

Thanks

 

Chris

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.