所以,我在PHP中的总的n00b(和后端的编程一般),但我从来不认为我想建立一个有效的数据库,用户可以搜索客户端作为个我的第一个Web开发级决赛项目。
无论如何,我做了一个本地主机我的网站和数据库,虽然过了好一会儿,我把一切都完全正常。 当我试图将其移动到我的虚拟主机提供商,但是,一切都开始断裂了,因为,以前不知道的我来说,虚拟主机提供商使用PHP 5.2。 我已经能够操纵一切可疑的安全(我知道,我知道,但我绝望了,而且也只在这里假数据无论如何)的一些功能的解决方案,但有一件事我不能找到一个解决为是mysqli_fetch_all()。 我接到一个电话未定义功能mysqli_fetch_all()错误。
我用它为我的搜索功能:当您搜索用户时,该功能将所有匹配信息的行,并把它在一个阵列,并在最后,所有的结果阵列合并成一个数组,它是回来。 我就是这么做的,这样是没有输入搜索条件将被忽略,而不是返回一个错误(NULL一直是我的存在,这整个项目的祸根)。
该网站可浏览http://webinfofinal.webatu.com/profiles.html所以你看到的我的工作和代码如下。 有什么建议么? 我试过其他抓取功能,但它们只返回第一个匹配行。
if ($firstName != null){
$result2 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where firstName = '$firstName' ");
$query2 = mysqli_fetch_all($result2,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query2);
}
if ($lastName != null){
$result3 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where lastName = '$lastName' ");
$query3 = mysqli_fetch_all($result3,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query3);
}
if ($eMail != null){
$result4 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where eMail = '$eMail' ");
$query4 = mysqli_fetch_all($result4,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query4);
}
if ($age != null){
$result5 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where age = '$age' ");
$query5 = mysqli_fetch_all($result5,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query5);
}
if ($classification != null){
$result6 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where classification = '$classification' ");
$query6 = mysqli_fetch_all($result6,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query6);
}
if ($major != null){
$result7 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where major = '$major' ");
$query7 = mysqli_fetch_all($result7,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query7);
}
if ($faveAnimes != null){
$result8 = mysqli_query($con, "SELECT displayName , firstName , lastName , eMail , age , classification , major , faveAnimes FROM a2097702_fac.members where faveAnimes = '$faveAnimes' ");
$query8 = mysqli_fetch_all($result8,MYSQLI_ASSOC);
$search = array_merge_recursive($search, $query8);
}
if ($search != null){
echo "<html>";
echo "<head>";
echo"<title> Anime Club Search Results | Web Info Final Project </title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"webinfofinal.css\">";
echo "</head>";
echo "<div class=\"content\" style=\"width:50%; margin-left:-20%;\">";
echo "<div class=\"header\">";
echo "<p></p><p>Your search results are below. </p>";
echo "</div>";
echo "<pre>";
print_r($search);
echo "</pre>";
echo "<p>End of results. <a href=\"profiles.html\">Search again?</a></p>";
echo "<a href=\"login.html\"><input type='button' value='Update My Profile' id='updateProfile'></a>";
echo "<a href=\"logout.php\"><input type='button' value='Log Out' id='logout'></a>";
echo "</div>";
echo "</html>";
}