![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Mar 2007
Posts: 33
Rep Power: 0
![]() |
Combo Box selected item - from DB
Hey guys,
I have a database which contains a list of game names, i am reading it and using it to create a combo box in a webpage. When a user submits an item, and then views the same page again, i want that item to be the one automatically selected in the combo box. i know that this creates a selectable item: <option value="3">Age Of Empires 2</option> and that this: <option value="3" selected>Age Of Empires 2</option> will force that item to be the automatically selected item. but i cannot get this to work dynamically based on the database reads, this is the code (at its current state, i have mashed with it that much just seeing what effect different things have) but havent really gotten any closer: <?php session_start(); ?>
<html>
<head>
<title>Update Your Games</title>
<body>
<Form method="post" action="AddGames.php">
<fieldset>
<legend>Update Your Games - TEST</legend>
<?php
include ("Functions.php");
Global $Option;
$Username = safe_output($_SESSION['username']);
$GamesList = mysql_query("SELECT * FROM games ORDER BY GameName");
$ViewMyGames = mysql_query("SELECT Game1,Game2,Game3,Game4,Game5 FROM members WHERE Username='$Username'");
If (!$GamesList) {
Print "Unable to retrieve games list";
} Else {
$a = mysql_fetch_array($GamesList);
$ChosenGames = mysql_fetch_array($ViewMyGames);
print sizeof($a);
While ($row = mysql_fetch_array($GamesList)) {
If ($ChosenGames['Game1'] == $row['GameID']) {
$Option = $Option.'<option value="'.$row['GameID'].'" selected>'.$row['GameName'].'</option><br/>';
} ElseIf ($ChosenGames['Game2'] == $row['GameID']) {
$Option = $Option.'<option value="'.$row['GameID'].'" selected>'.$row['GameName'].'</option><br/>';
} ElseIf ($ChosenGames['Game3'] == $row['GameID']) {
$Option = $Option.'<option value="'.$row['GameID'].'" selected>'.$row['GameName'].'</option><br/>';
} ElseIf ($ChosenGames['Game4'] == $row['GameID']) {
$Option = $Option.'<option value="'.$row['GameID'].'" selected>'.$row['GameName'].'</option><br/>';
} ElseIf ($ChosenGames['Game5'] == $row['GameID']) {
$Option = $Option.'<option value="'.$row['GameID'].'" selected>'.$row['GameName'].'</option><br/>';
} Else {
$Option = $Option.'<option value="'.$row['GameID'].'">'.$row['GameName'].'</option><br/>';
}
$i = 1;
While ($i <= 5) {
Print "<p>Game $i:<br/>";
Print '<select name="game'.$i.'"><br>';
Print $Option;
Print "</select></p>";
$i = $i + 1;
}
}
}
mysql_close($con);
?>
</p>
<input type="submit" name="action" value="send" />
</p>
</fieldset>
</form>
<?php
print_menu();
?>
</body>
</html>If someone has a nice simple example script for me to go by, that would be much appreciated. thanks /tAK |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| error 3 Expected end-of-statement | m0rb1d | Other Scripting Languages | 0 | Dec 12th, 2006 10:05 AM |
| Confusion With Pointers and Arrays | JawaKing00 | C | 10 | Sep 14th, 2006 7:33 AM |
| anoying problem with a combo box | cloud- | Visual Basic | 12 | May 28th, 2005 1:20 PM |
| Java Combo Boxes | Vengeance | Java | 0 | May 4th, 2005 9:02 AM |
| What are advantages of Data Combo and data list over simple combo and list box? | sham | Visual Basic | 1 | Apr 12th, 2005 4:11 AM |