×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Need help in how to create a Dropdown from a MySql table

Need help in how to create a Dropdown from a MySql table

Need help in how to create a Dropdown from a MySql table

(OP)
I have a table that in one column shows the results of a query. There could be many rows built. I need to create a form with this table and add two columns, each cell needs to be a dropdown from another table in the same DB. Basically I am linking the three columns to gether. At some point I will need to take the row info and create a file out of the information. That can be later tho.

Thanks for any idead / help

RE: Need help in how to create a Dropdown from a MySql table

Run a query to get the items for the dropdowns, then use the results in a loop to build the dropdown:

CODE

$query_results = mysql_query(...);

//build dropdown html
$html = "<select name='dropdownname'>";
while($row = mysql_fetch_row($query_results))
{
//build dropdown items:
$html.="<option value='" . $row['columnname'] . ">" . $row['columnnamefortext'] . "</option>";
} //close dropdown html $html.="</select>";

$html will then contain the dropdown html and you can echo it out anywhere you want.

----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

RE: Need help in how to create a Dropdown from a MySql table

(OP)
Thanks I will try that!

RE: Need help in how to create a Dropdown from a MySql table

(OP)
OK I figured out how to get the dropdown info from my queries and actually have them on my page. The next step is to have them be part of the overall table in each row. I have tried putting the select statement into the row but the page fails. How would I do this? Here is my page so far.

echo "<table border='3'>
<tr>
<th>Extension #</th>
<th>Secret</th>
<th>MAC Address</th>
<th>Template</th>

</tr>";
while($row = mysql_fetch_array($result2))
{
echo "<tr>";
echo "<td>" . $row['extension'] . "</td>";
echo "<td>" . $row['secret'] . "</td>";
echo "<td>" . $row[''] . "</td>";
echo "<td>" . $row[''] . "</td>";
echo "</tr>";
}
echo "</table>";

?>
<p>
<select name="phone">
<?php
while($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['id'] . '">' . $row['mac'] . '</option>';
}
?>
</select>
<select name="template">
<?php
while($row = mysql_fetch_array($result1)) {
echo '<option value="' . $row['id'] . '">' . $row['templatename'] . '</option>';
}
?>
</select>

</p>
<?php
mysql_close($link);

I want the phone and the template select in the 3rd and 4th columns of the table. The user will select on a per row basis which values they want. Ultimately this page will be a form for creating files.

Thanks for any help, thoughts


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close