知道为什么这显示为 null 的结果吗?我猜这与我在进行查询之前放置 $link 的位置有关,但必须这样做,对吗?
function getcatposts($cat_id) {
$qc = @mysqli_query($link, "SELECT * FROM topics WHERE topic_cat='$cat_id'");
while($row = mysqli_fetch_array($qc)) {
$topic_title=$row['topic_subject'];
$topic_id=$row['topic_id'];
}
$qc2 = @mysqli_query($link, "SELECT * FROM categories WHERE cat_id='$cat_id'");
while($row2 = mysqli_fetch_array($qc2)) {
$cat_name=$row2['cat_name'];
}
更新代码:
function getcatposts($cat_id) {
$link = mysqli_connect("localhost", "lunar_lunar", "", "lunar_users");
$qc = mysqli_query($link, "SELECT * FROM topics WHERE topic_cat='$cat_id'");
while($row = mysqli_fetch_array($qc)) {
$topic_title=$row['topic_subject'];
$topic_id=$row['topic_id'];
}
$qc2 = mysqli_query($link, "SELECT * FROM categories WHERE cat_id='$cat_id'");
while($row2 = mysqli_fetch_array($qc2)) {
$cat_name=$row2['cat_name'];
}
echo $cat_name;
echo '<br />';
echo $topic_title;
echo '<br />';
echo $topic_id;
}
新问题是它的显示如下:http: //gyazo.com/43e8a91b9e0cf4f5e413536907891dcf.png 当数据库看起来像这样时:http: //gyazo.com/1ead8bd0f150838dae3ee4a476419679.png
它应该显示所有三个,这是一个函数,意味着它将继续重做所有代码,直到它无法查询更多数据。有任何想法吗?