php - 我的功能没有运行,我错过了什么?
问题描述
我正在为我的网站制作朋友列表,我需要多次从数据库中获取用户的朋友,所以我认为我需要一个功能来整理东西。我的代码正确显示了我的所有信息,直到我将它放入一个函数然后它停止工作。我没有收到任何错误消息,内容只是消失了。我在其他 php 文档中的其他函数工作正常,所以我不知道问题是什么。
我在 1 个文件夹中有 4 个关键的 php 文档。Friends.php header.php 包含/dbh.inc.php 和包含/friends.inc.php
头文件.php
<?php
require 'includes/dbh.inc.php';
session_start();
date_default_timezone_set('America/Chicago');
include 'includes/posts.inc.php';
include 'includes/friends.inc.php';
?>
包括/dbh.php
<?php
$servername = "na";
$dBUsername = "na";
$dBPassword = "na";
$dBName = "na";
$conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBName);
if (!$conn) {
die("Connection failed: ".mysqli_connect_error());
}
朋友.php
echo "<div class='friendStatus1'>";
echo "Following";
status1($conn);
echo "</div>";
最后包括/friends.inc.php
<?php
// status1
function status1($conn) {
$stat1sql = "SELECT * FROM friends WHERE (user1 = ?) AND status = 1";
$stat1stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stat1stmt, $stat1sql)) {
echo "error1";
}
else {
mysqli_stmt_bind_param($stat1stmt, "i", $userID);
mysqli_stmt_execute($stat1stmt);
$stat1result = mysqli_stmt_get_result($stat1stmt);
while ($stat1row = mysqli_fetch_assoc($stat1result)) {
$userID == $stat1row['user1'];
$otheruserID = $stat1row['user2'];
$otheruserNamesql = "SELECT userName FROM users WHERE userid = ?";
$otheruserNamestmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($otheruserNamestmt, $otheruserNamesql)) {
echo "error";
}
else {
mysqli_stmt_bind_param($otheruserNamestmt, "s", $otheruserID);
mysqli_stmt_execute($otheruserNamestmt);
$otheruserNameresult = mysqli_stmt_get_result($otheruserNamestmt);
while ($otheruserNamerow = mysqli_fetch_assoc($otheruserNameresult)) {
echo "<div class='friendBox'>";
echo "<a href='home.php?user=".$otheruserNamerow['userName']."'>".$otheruserNamerow['userName']."</a>";
echo "</div>";
}
}
}
}
}
?>
解决方案
推荐阅读
- java - 通过 JNI 创建和设置数组
- c# - 为什么没有支持的机制可用于使用 Xamarin.iOS 在 C# 中创建可从 Objective-C 调用的库。?
- gradle - Android 构建失败:无法解析配置“:debugCompileClasspath”的所有文件
- python-3.x - - 不支持的操作数类型:“str”和“int”:在比较爬网网站上的基本域名和子域名时
- c# - IEnumerable 上的自定义扩展方法
- java - 在java中的n-ary树中找到一个不包含最大子节点数的节点
- c++ - 打破 While 循环 C++
- javascript - 如何在 React 中从非 React 库中渲染 div 对象?
- git - 将分支恢复到旧位置的最佳方法是什么?
- xml - 修改python-docx中paragraph.style._element.xml中的XML