Jump to content

Recommended Posts

Hey

I have a table where there are some rows i need to be displayed in a dropdown form box.

Table name: wof_best
Row names: wof_best_gk, wof_best_d1,wof_best_d2, wof_best_d3, wof_best_d4

So 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.
Link to comment
https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/
Share on other sites

[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]
Link to comment
https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134751
Share on other sites

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 database
include('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 code
echo "<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.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134755
Share on other sites

[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.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134759
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134761
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134822
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134852
Share on other sites

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]<?php
echo "<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

Link to comment
https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-134880
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/29383-rows-in-dropdown-menu/#findComment-135444
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.