Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

EdLentz

Technical User
Mar 20, 2002
85
US
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
 
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:
[indent]$html.="<option value='" . $row['columnname'] . ">" . $row['columnnamefortext'] . "</option>";[/indent]
}

//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
 
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


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top