JJohnsenDK Posted December 4, 2006 Share Posted December 4, 2006 HeyI have a table where there are some rows i need to be displayed in a dropdown form box.Table name: wof_bestRow names: wof_best_gk, wof_best_d1,wof_best_d2, wof_best_d3, wof_best_d4So i need the rows to be listed down in a drop down menu.My code is like this(totally wrong, but might be a guideline).[code] <?php $hent_pos = ("SELECT * FROM wof_best"); ?> <td width="70%"> <SELECT name"wof_best"> <option value="position">Vælg position</option> <?php while ($vis_pos = mysql_fetch_array($hent_pos)){ ?> <option value="<?php echo $$hent_pos?>"><?php echo $hent_pos?></option> <?php } ?> </SELECT> </td>[/code] Hope you understand what im asking. Else plz ask for more detailed version. Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/ Share on other sites More sharing options...
chiprivers Posted December 4, 2006 Share Posted December 4, 2006 [code]<td width="70%"><select name="wof_best"><?php$query = "SELECT * FROM wof_best";$result = mysql_query($query);while($row = mysql_fetch_array($result)) {echo "<option value=\"".$row['hent_pos']."\">".$row['hent_pos']."</option>\n";}?></select></td>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134751 Share on other sites More sharing options...
HuggieBear Posted December 4, 2006 Share Posted December 4, 2006 I got the impression that your terminology was wrong. When you say row names, do you really mean column names, as rows don't have 'names'.If you meant column names, then give this a try.[code]<?php// Connect to your databaseinclude('dbconnect.php');// Run the query to get the field names$sql = "SHOW COLUMNS FROM wof_best";$result = mysql_query($sql);// Start to echo the select codeecho "<select name='columns'>\n";while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<option value='".$row['Field']."'>".$row['Field']."</option>\n";}echo "</select>\n";?>[/code]There are certain to be some minor security issues with this, as I can't see that it's good practice to make your column names visible to the public, but the code should work in theory.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134755 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 Thats not working... hent_pos isnt a row in the table... I need all the rows in the wof_best table to be displayed in the dropdown menu. Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134756 Share on other sites More sharing options...
chiprivers Posted December 4, 2006 Share Posted December 4, 2006 perhaps you can explain your database a bit better so we know what we are working with.What columns (fields) do you have and how many records are there? Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134757 Share on other sites More sharing options...
HuggieBear Posted December 4, 2006 Share Posted December 4, 2006 [quote author=JJohnsenDK link=topic=117282.msg478348#msg478348 date=1165231794]Thats not working... hent_pos isnt a row in the table... [/quote]That's what I suspected, when you say rows, you mean columns... Give what I posted a try.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134759 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 sry didnt see the last reply before i wrote. Yeah i meant colums and that seems to work. But if its a secruity problem how should i do it then?What i need is to update the colums with a name. For example:Name: Peter Lassen.He needs to go into the colum wof_best_d1. For me to do this, i need to show the colums names, dont i?Or is there a smarter way?I have 12 colums in wof_best table. wof_best_id, wof_best_gk, wof_best_d1, wof_best_d2,wof_best_d3 wof_best_d4, wof_best_m1, wof_best_m2, wof_best_m3, wof_best_m4, wof_best_a1, wof_best_a2.What i need is a football (soccer) team of the year. Where elleven players a selected. I allready have the players in a database table called, wof_pl. In this wof_pl i need the colum wof_pl_name to be posted into one of the colums in wof_best_d1 for example, if the player is picked in the dropdown menu. The dropdown menu where i want the colums from wof_best. Is this somehow understandable? Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134761 Share on other sites More sharing options...
HuggieBear Posted December 4, 2006 Share Posted December 4, 2006 It's not that much of a security risk, I did say minor. Even with what you have people won't know your database name or table name.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134763 Share on other sites More sharing options...
chiprivers Posted December 4, 2006 Share Posted December 4, 2006 Have you sorted this now JJohnsenDK?From what I can gather, the form you are trying to create is something to do with the team selected for a Fantasy Football League. Is this form for a user to select their team from a list of players available or to display the selected team of a user? Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134822 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 This is for admins on my website to select players who should be on the "Team of the year".For example Peter Lassen again. He is created in the database and is showed at the website as a player. On the website i also have a "Team of the year" section. Its here i want Peter Lassen to be shown if he is picked in that dropdown menu. If he gets picked as Attacker1 he is shown as Attacker1 in this "Team of the year". For "team of the year" i have the wof_best table in database to stored the players.There is a team for every season. Like season 2006, 2005, 2004 and so on. So i have a input in my form field where i select the year the player should be shown in. Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134852 Share on other sites More sharing options...
craygo Posted December 4, 2006 Share Posted December 4, 2006 Well I get what you mean but you may want to maybe narrow down your players. I assume all the playares are in a table of there own. Instead of having ALL the players show up in the dropdown list you should add another field which shows their position. That way you could narrow down the players in a certain postition. And also you have to query the players table not the table you want to add the player to. You are looking to add a player for a position so you have to query the player table.[code]<?phpecho "<select name=best_gk>";echo "<option value=0>--Please select best Goal Keeper--</option>";$bestgk = "SELECT * FROM player_table WHERE position = 'gk'"; $bkres = mysql_query($bestgk) or die(mysql_error()); while($gk = mysql_fetch_assoc)){ echo "<option value='".$gk['player_id']."'>".$gk['name']."</option>"; }echo "</select>";?>[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134880 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 yeah okay, but how would you store the name of the best goalkeeper into the wof_best table(the table which holds all the "team of the year")? Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134887 Share on other sites More sharing options...
chiprivers Posted December 4, 2006 Share Posted December 4, 2006 You need a table: playerswith columns: player_ID, name, position (amongst what ever else you want)second table: team of the yearwith columns: toty_ID, year, position, player_ID Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134891 Share on other sites More sharing options...
craygo Posted December 5, 2006 Share Posted December 5, 2006 Well after you choose all of your players in the form with all the dropdown list, you would submit that to another page which would submit all your players. In order to help you out I would need the table structure of both your tables.Is this going to be like a voting system where everyone submits their best team then you add up all the votes and print out the best team??I can help you with the code but like I said I would need your table structure to do so.Ray Quote Link to comment https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-135444 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.