Hi,
I am trying to populate a table on a webpage with the list from my industry_list table. This list is one of many that will display the "active" list that I have in the table. I am trying to do this in dreamweaver.
When the list is retrieved, it needs to add a dropdown list (3 month, 6 months etc) and a checkbox. I need to update my industry table with the values that the user selects.
I know what it needs to look like, but don't know how to get there. If there is anyone out there that might help, or point me in the right directions i would be grateful.
Here is a link to a screenshot of what I am trying to do. http://www.knoetze.plus.com/university/ ... endump.JPG
Many thanks,
Brendon
[SOLVED] Displaying list from mysql with dropdown
Moderator: General Moderators
-
brendonknoetze
- Forum Newbie
- Posts: 5
- Joined: Wed Mar 16, 2005 4:50 pm
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Dreamweaver ..

the "list" retrival and drop down is a simple selection loop similar to the following:
handling the submission is as simple as $_POST['mydropdown'] if your form used the post method.
the "list" retrival and drop down is a simple selection loop similar to the following:
Code: Select all
// ...
$query = mysql_query('SELECT * FROM `some_table`') or die(mysql_error());
if(!$query || mysql_num_rows($query) <= 0)
{
echo 'no data found.';
}
else
{
$check = 'hi'; // pre-checked value (may come from a database)
$out = '<select name="e;mydropdown"e;>';
while($row = mysql_fetch_assoc($query))
{
$out .= '<option value="e;' . $rowї'fieldval'] . '"e;' . ($check == $rowї'fieldval'] ? ' checked="e;checked"e;' : '') . '>' . $rowї'fieldname'] . '</option>' . "e;\n"e;;
}
echo $out . '</select>';
}selection is not made by this code
Code: Select all
echo " <TABLE class = sort-table width = 100% border = 1>";
echo "<TR>";
echo"<thead>";
echo "<TD align = center>Appointee</TD>";
echo "<TD align = center>Organization</TD>";
echo "<TD align = center>Person</TD>";
echo "<TD align = center>Purpose</TD>";
echo "<TD align = center>Date</TD>";
echo "<TD align = center>Status</TD>";
echo "</thead>";
echo "</TR>";
while($row = mysql_fetch_object($resultappoint))
{
echo "<tr>";
echo "<td width= 15% p align = center>" ."<a href='appointmentedit.php?$row->appointment_id'> $row->user_id</a>"."</td>";
echo "<td align = center>". $row->org_id."</td>";
echo "<td align = center>". $row->contact_person."</td>";
echo "<td align = center>". $row->purpose."</td>";
echo "<td p align =center>". $row->appoint_date. "</td>";
echo "<td p align = center>";
//echo "<select>";
$querystatus = "SELECT * FROM appointmentstatus";
$resultstatus = mysql_query($querystatus) or die('Error, query failed dfsdf');
$check = 'Pending';
$out = '<select name="mydropdown">';
while($row2 = mysql_fetch_assoc($resultstatus))
{
$out .= '<option value="' . $row2['status_name'] . '"' . ($check == $row2['status_name'] ? ' checked="checked"' : '') . '>' . $row2['status_name'] . '</option>' . "\n";
}
echo $out . '</select>';
echo "</tr>";
}
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
provided the outer loop is running correctly, the <select> tags themselves should display at least. If $resultstatus contains at least 1 record, an option should also exist.
I do have to apologize though. I wrote a slight error in my code previously.. it should be selected="selected" not checked="checked".
When I have a select to create from a table that doesn't change throughout the page, or loop it's used in, I will cache off the results into a variable so I don't redundantly query the database..
I do have to apologize though. I wrote a slight error in my code previously.. it should be selected="selected" not checked="checked".
When I have a select to create from a table that doesn't change throughout the page, or loop it's used in, I will cache off the results into a variable so I don't redundantly query the database..
Problem Solve
Code: Select all
while($row = mysql_fetch_object($resultappoint))
{
echo "<tr>";
echo "<td width= 15% p align = center>" ."<a href='appointmentedit.php?$row->appointment_id'> $row->user_id</a>"."</td>";
echo "<td align = center>". $row->org_id."</td>";
echo "<td align = center>". $row->contact_person."</td>";
echo "<td align = center>". $row->purpose."</td>";
echo "<td p align =center>". $row->appoint_date. "</td>";
echo "<td p align = center>";
echo "<select>";
$querystatus = "SELECT * FROM appointmentstatus";
$resultstatus = mysql_query($querystatus) or die('Error, query failed dfsdf');
while($row2 = mysql_fetch_object($resultstatus))
{
echo "<option value=$row2->status_name ";
if ( $row->status == $row2->status_name){
echo " selected " ;
echo ">$row2->status_name</option>" ;
}
else
{
echo ">$row2->status_name</option>" ;
}
}
echo "</select>";-
brendonknoetze
- Forum Newbie
- Posts: 5
- Joined: Wed Mar 16, 2005 4:50 pm
Thanks for your help - my solution
Thanks for all of you suggestions. Here is my solution.
Now - Here is my next delema, How do I get this data in to a table. What will the update sql query look like, as the select name and checkbox name are all dianamic?
Any help would be GREAT.
feyd | Please review how to post code using
Code: Select all
<?php
$linkID = mysql_connect("localhost", "root", "durban12");
mysql_select_db("talent", $linkID);
$resultID = mysql_query("SELECT fun_list_id, fun_list_name, fun_checkbox
FROM function_list where fun_list_active = '1'", $linkID);
$row = mysql_fetch_assoc($resultID);
print "<font face='Arial, Helvetica, sans-serif'> <table border=\"1\"><tr><th><font size='1' >Function ID</th>";
print "<th><font size='1'>Functional Experience</th>";
print "<th><font size='1'>Year Exp.</th>";
print "<th><font size='1'>Core</th></tr>";
for ($x = 0; $x <mysql_num_rows($resultID); $x++)
{
$row = mysql_fetch_assoc($resultID);
print "<tr>";
print "<td><font size='1'>" . $row[fun_list_id] ."</td>";
print "<td><font size='1'>" . $row[fun_list_name] ."</td>";
print "<td><font size='1'> <select name='select".$row[fun_list_id]."'>
<option value='0'>None</option>
<option value='1'><6 months</option>
<option value='2'>6-12 months</option>
<option value='3'>18 months</option>
<option value='4'>2-3 years</option>
<option value='5'>3-4 years</option>
<option value='6'>>5 years</option>
</select>";
print "<td> <input type='checkbox' name='checkbox".$row[fun_list_id]."'/></td>";
print "</tr>";
} //close for loop
print "</font></table>";
mysql_close($linkID);
?>Any help would be GREAT.
feyd | Please review how to post code using
Code: Select all
andCode: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]