【发布时间】:2014-08-26 20:33:24
【问题描述】:
在我的网站中,用户可以创建池(组)。显然,当他们创建池时,池信息(池名称等)会发送到我的数据库。然后在用户的配置文件中,我从数据库中检索他们所在的所有池并将它们显示在页面上。
但是,目前,这些仅显示为文本。我希望将它们超链接到作为池配置文件的单独页面。谁能帮我做到这一点?我的代码如下。
<?php
session_start();
$conn = mysqli_connect("localhost","root","root","UltimateLeague");
$query = ("SELECT * FROM userpool WHERE userid=".$_SESSION['user_id']."");
$result = mysqli_query($conn, $query); //Finding the pools that the current user is in
$poolid = array(); //Creating an array of these pools
while ($row = mysqli_fetch_assoc($result)) {
$pool_id[] = $row['pool_id'];
}
$ids = join(',',$pool_id); //Finding the names of these pools in a separate table
$query2 = "SELECT * FROM pools WHERE pool_id IN ($ids)";
$result2 = mysqli_query($conn, $query2);
$pool_name = array(); //Creating an array of these names
if (mysqli_num_rows($result2) > 0) {
while ($row2 = mysqli_fetch_assoc($result2)) {
$pool_name[] = $row2['pool_name'];
}
}
?>
然后,池的显示:
<html>
<p><h5>Below is a list of pools that you are currently in.</h5></p>
<ul>
<?php foreach( $pool_name as $pool): ?>
<ul>
<?= $pool ?>
</ul>
<?php endforeach; ?>
</ul>
</html>
那么在这个循环中,如何将每个 $pools 链接到单独的页面?
提前致谢。
【问题讨论】:
-
您应该使用
JOIN而不是两个单独的查询。 -
我对这个很陌生,所以我什至不知道你能做到这一点。谢谢你。但是,它并不能完全解决我的超链接问题。
-
我没说过,只是建议如何正确使用数据库。
标签: php arrays mysqli hyperlink