【发布时间】:2021-06-19 06:50:30
【问题描述】:
我有以下功能。
我正在尝试从 3 个没有任何关系的不同表中获取数据。
除了a href 属性外,一切正常。
我需要根据表格设置链接。 IE:如果insert_into_index = 1 in table performances我需要链接到performance.php,如果insert_into_index = 1 in table education,链接应该是education.php,如果insert_into_index = 1 in Artists_works链接应该是art.php
function intro_news($lang) {
global $connection;
$lang = $_GET['lang'];
$sql = "
SELECT id, title, title_en, insert_into_index, ordering FROM performances
WHERE insert_into_index=1
UNION
SELECT id, title, title_en, insert_into_index, ordering FROM education
WHERE insert_into_index=1
UNION
SELECT id, title, title_en, insert_into_index, ordering FROM artists_works
WHERE insert_into_index=1
ORDER BY ordering ASC
";
$query = mysqli_query($connection,$sql) or die(mysqli_error($connection));
$count = mysqli_num_rows($query);
if ($count > 0) {
echo '<div class="grid">';
echo '<div class="row justify-content-center">';
while ($row = mysqli_fetch_array($query)) {
echo '<div class="col-sm-12 col-md-6 col-lg-3 margin-wrapp rotate my-auto">';
// HERE IS THE ISSUE
if ($row['insert_into_index'] == '1') {
echo '<a href="';
echo 'performance';
echo '.php?lang='.$lang.'&name='.$row['id'].'">';
}
if ($row['insert_into_index'] == '1') {
echo '<a href="';
echo 'education';
echo '.php?lang='.$lang.'&name='.$row['id'].'">';
}
if ($row['insert_into_index'] == '1') {
echo '<a href="';
echo 'art';
echo '.php?lang='.$lang.'&name='.$row['id'].'">';
}
// ISSUE
echo '<span class="name">';
if ($lang === "sk") {
echo $row['title'];
}
if ($lang === "en") {
echo $row['title_en'];
}
echo '</span>';
echo '</a>';
echo '</div>';
} // while loop
echo '</div>';
echo '</div>';
}
}
现在的结果是:
<a href=art.php?lang=sk&name=1>bla bla</a>
<a href=art.php?lang=sk&name=1>bla bla</a>
<a href=art.php?lang=sk&name=4>bla bla</a>
预期结果应该是:
<a href=performance.php?lang=sk&name=1>bla bla</a>
<a href=education.php?lang=sk&name=1>bla bla</a>
<a href=art.php?lang=sk&name=4>bla bla</a>
感谢您的帮助。 非常感谢。
【问题讨论】:
-
我很好奇你为什么不想要关系。