一开始,每个人都有 2 种语言的消息(chimessage和engmessage)保存到数据库中。
他们每个人都选择了一种首选语言(chi 或 eng)。在显示页面中,我试图用他们的首选语言显示每个人的消息。例如,如果人 A 更喜欢 eng,页面将只显示 engmessage。
PS 显示页面会包含针对不同人的engmessage 和 chimessage
我想知道我该怎么做,我正在考虑使用 if/else 语句。
PS 我知道我在使用已弃用的 mysql,仍在尝试学习 php,请多多包涵
<?php
include('connect-db.php');
$result = mysql_query("SELECT * FROM table
WHERE language ='Chi' OR language ='Eng'");
while($row = mysql_fetch_array( $result ,MYSQL_ASSOC)) {
echo "<tr>";
echo '<td width="200px">' . $row['people'] . '</td>';
echo '<td width="200px">' . $row['language'] . '</td>';
echo '<td>' . $row['chimessage'] ."<br />";
echo '<td>' . $row['engmessage'] ."<br />";
}
echo "</tr>";
echo "</table>";
?>
预期结果
People Language Msg
A Chi 物理治療
B Eng Physiotherapy
像这样改变你的代码
<?php
include('connect-db.php');
$result = mysql_query("SELECT * FROM table
WHERE language ='Chi' OR language ='Eng'");
echo "<table>";
while($row = mysql_fetch_array( $result ,MYSQL_ASSOC)) {
echo "<tr>";
echo '<td width="100px">' . $row['id'] . '</td>';
echo '<td width="200px">' . $row['people'] . '</td>';
if($row['language'] == 'Chi')
{
echo '<td>' . $row['chimessage'] ."</td>";
}
else if($row['language'] == 'Eng')
{
echo '<td>' . $row['engmessage'] ."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句