【发布时间】:2018-09-24 09:03:51
【问题描述】:
我有这种情况:
我的数据库的表叫做 reteconsolare 并且有这些字段:
身份证 斯塔托 西塔 印迪里佐 电话 电子邮件 网址 马帕 Descrizione(这不是真正的展示。我仅用于在 Sito 和 Mappa 链接上显示图像的标题)
此时一切正常,只是当“Stato”有更多“Citta”时,我希望在“Citta”列中出现一个输入选择,其中包含从 A 订购的 Stato 的所有可用名称到 Z 并在更改选择时,还应显示正确的 Indirizzo、Telefono、Email、URL、Mappa。
以下是我重复这些值的实际代码。
例如:
比利时 |布鲁塞尔
比利时 |沙勒罗瓦
<?Php
mysqli_set_charset($connessione, 'utf-8');
$sql = "SELECT * FROM reteconsolare ORDER BY Stato, Citta";
$query = $connessione->query($sql) ;
while ($row = $query->fetch_assoc()) {
$stato=sprintf( $row["Stato"]);
$citta=sprintf( $row["Citta"]);
$indirizzo=sprintf( $row["Indirizzo"]);
$descrizione=sprintf( $row["Descrizione"]);
$email=sprintf( $row["Email"]);
$telefono=sprintf( $row["Telefono"]);
$mappa=sprintf( $row["Mappa"]);
$link=sprintf( $row["URL"]);
$id=sprintf( $row["ID"]);
?>
<tr>
<td width="20%"><ts><?Php echo($stato) ?></ts></td>
<td width="20%"><ts><?Php echo($citta) ?></ts></td>
<td width="30%"><ts><?Php echo($indirizzo) ?></ts></td>
<td width="10%"><ts><?Php echo($telefono) ?></ts></td>
<td width="10%"><ts><?Php echo emailize($email) ?></ts></td>
<td width="5%" align="center"><?Php echo(' <a target=_blank href='); echo($link); echo('>'); ?><img src="img/www.png" width="20" height="20" title="Link al sito del <?php echo ($descrizione);?>"></a></td>
<td width="5%" align="center"><?Php echo(' <a target=_blank href='); echo($mappa); echo('>'); ?><img src="img/Maps.png" width="20" height="20" title="Mappa del <?php echo ($descrizione);?>"></a></td>
</tr>
<?php } while ($row_news = $query->fetch_assoc());?>
<?php
function emailize($text)
{
$regex = '/(\S+@\S+\.\S+)/';
$replace = '<a href="mailto:$1">$1</a>';
return preg_replace($regex, $replace, $text);
}?>
我还搜索了另一种方法:不重复 Stato 的名称,并用其数据包裹每个城市。我试图玩mysql的group by ...但没有结果。无论如何,我不太喜欢这个解决方案。我认为我可能还需要知道 Ajax 来解决这个问题,但目前我无法学习它......提前谢谢。
【问题讨论】:
-
你可以查看我的答案是否适合你
标签: php mysql ajax html-select