我需要从mysql填充选择列表。 mysql表中有些行具有相同的值。
例如: 1-妈妈 2-PAPPA 1-KUS
我的选择下拉列表将显示数字1,1,4。 首先,我不想参与其中,我可以在我的选择中使用DISTINCT。 但是,当我在下拉列表中选择数字1时,我想要同时显示妈妈和妈妈。 PAPP-A。
我该怎么做? 我有一些代码:
//Sql select
$sql = "SELECT * FROM phpexcel";
//
$aResult = mysql_query($sql);
if($_REQUEST['frm_action'] == 3){
if ($_REQUEST['id'] == 0){
$id = $_REQUEST['id'];
$sqlCustomer = "SELECT * FROM phpexcel";
}
else{
$id = $_REQUEST['id'];
$sqlCustomer = "SELECT * FROM phpexcel WHERE id ='$id'";
}
$aCustomer = mysql_query($sqlCustomer);
}
?>
<html>
<head>
<script type="text/javascript">
function changeSID()
{
oForm = eval(document.getElementById("frmForm"));
iCustomerId = document.getElementById("objekt_nr").value;
url = "get_element_by_objekt.php?frm_action=3&id=" +iCustomerId;
document.location = url;
}
</script>
</head>
<body>
<form name="frmForm" id="frmForm" >
<table border="0" cellspacing="2" cellpadding="2" width="40%">
<tr>
<td align="right" ><strong>Objekt</strong></td>
<td align="left"><select name="objekt_nr" id="objekt_nr" onchange="javascript:changeSID();">
<option value="">Select</option>
<option value="0">All</option>
<?php
$sid1 = $_REQUEST['id'];
while($rows=mysql_fetch_array($aResult,MYSQL_ASSOC))
{
$id = $rows['id'];
$sid = $rows['objekt_nr'];
if($sid1 == $id)
{
$chkselect = 'selected';
}
else
{
$chkselect ='';
}
?>
<option value="<?php echo $id;?>"<?php echo $chkselect;?>><?php echo $sid;?></option>
<?php } ?>
</td>
</tr>
<?php if($_REQUEST['frm_action'] == 3) { ?>
<tr>
<td colspan="2">
<table style="border:1px solid #003366;" cellspacing="2" cellpadding="2" width="100%" bgcolor="#003366">
<tr bgcolor="#EFEFEF">
<td><b><font color='Red'>Objekt Nr</font></b></td>
<td><b><font color='Red'>Objekt Rev</font></b></td>
<td><b><font color='Red'>Element Nr</font></b></td>
</tr>
<?php
while($row1 = @mysql_fetch_array($aCustomer,MYSQL_ASSOC))
{
$sid = $row1['objekt_nr'];
$sname = $row1['objekt_rev'];
$age = $row1['element_nr'];
?>
<tr bgcolor="#FFFFFF">
<td><b><font color='#663300'><?php echo $sid;?></font></b></td>
<td><b><font color='#663300'><?php echo $sname;?></font></b></td>
<td><b><font color='#663300'><?php echo $age;?></font></b></td>
答案 0 :(得分:0)
SELECT id, GROUP_CONCAT(objekt_nr SEPARATOR ' ') AS objekt_nr FROM phpexcel GROUP BY id;
应该做的伎俩。
会回复你:
1 Pappa Mamma
2 Kus
答案 1 :(得分:0)
此选择
SELECT DISTINCT
objekt_nr, GROUP_CONCAT(DISTINCT element_nr ORDER BY element_nr) AS element_nr_list
FROM phpexcel
group by objekt_nr
ORDER BY objekt_nr
给我这个:
N111
10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29
N123456
1,2,3,4,5,6,7,8,9