Mr Chris Posted July 14, 2007 Share Posted July 14, 2007 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> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 14, 2007 Share Posted July 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
Mr Chris Posted July 14, 2007 Author Share Posted July 14, 2007 Thanks, OK Here Goes... Here's my database: 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 Quote Link to comment 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.