我从名为Route and Step的MYSQL
表中选择了两列。每条路线都有多个与之相关的步骤。我想创建一个下拉菜单,其格式类似于以下内容:(Route:Step)。我将两列中的所有值存储到临时数组中。如何以我所述的格式显示结果?我已经有一个只有步骤的下拉菜单,但我也喜欢要显示的路线。
// Get step and route list according to flow
$d_step_list = array();
$query= "SELECT routes.route, steps.step ".
"FROM steps ".
"LEFT JOIN routes_steps_cross ON steps.serial_step = routes_steps_cross.serial_step ".
"LEFT JOIN routes ON routes.serial_route = routes_steps_cross.serial_route ".
"LEFT JOIN flows_routes_cross ON flows_routes_cross.serial_route = routes.serial_route ".
"LEFT JOIN flows ON flows.serial_flow = flows_routes_cross.serial_flow ".
"WHERE flows.serial_flow = $s_flow AND routes_steps_cross.active = 1 ".
"ORDER BY routes.serial_route, steps.serial_route ";
if ($show_query == 1) { print "<font size=\"-1\">".$query."</font><br>\n";}
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// First fill with blank data.
$d_step_list[] = "";
while ($temp_data = mysql_fetch_row($result)) {
$d_step_list["route"] = $temp_data[0];
$d_step_list["step"] = $temp_data[1];
}
print "<tr>\n";
print "<th bgcolor=\"#E9E9E9\"><font size=\"-1\">Disposition Step</th>\n";
print "<td align=\"center\"><font size=\"-2\">\n";
print " <br><select name=\"d_step\">\n";
foreach($d_step_list as $step1_selected)
{
if ($d_step == $step1_selected)
{
print "<option value=\"$step1_selected\" selected=\"1\">$step1_selected\n";
}
else
{
print "<option value=\"$step1_selected\">$step1_selected\n";
}
}
print "</select>\n";
print "</td>\n";
print "</tr>\n";
答案 0 :(得分:0)
每次循环都会覆盖相同的数组值。它应该是:
while ($temp_data = mysql_fetch_assoc($result)) {
$d_step_list[] = $temp_data['route'].":".$temp_data['step'];
}
请注意,您需要将元素设置为字符串,以便稍后将其与$d_step
进行比较,这样您就可以在打印时将其展开。