gpt4 book ai didi

php - MySQL 资源错误?

转载 作者:行者123 更新时间:2023-11-29 14:34:34 25 4
gpt4 key购买 nike

我正在开发一个用于教育用途的网站,当我尝试构建一个执行某些逻辑的文件时遇到了一些错误。

基本上,该代码旨在获取 3 个数据值,如果仅存在第一位数据,则​​运行 x 查询,如果存在第一个和第二位,则运行 y 查询,依此类推,直到它对 GET 数据运行 8 次测试。对于一些背景信息,level = 一个类(class)的学习水平(IGCSE、IB、A-Levels),Subject 是一门学科(数学、英语、科学),School 是学校的名称。

数据库结构如下:

'id' INT(11)
'title' VARCHAR(255)
'description' VARCHAR(1000)
'filename' VARCHAR(255)
'uploader' VARCHAR(255)
'school' VARCHAR(255)
'subject' VARCHAR(255)
'level' VARCHAR(255)
'downloads' VARCHAR(20)
'views' VARCHAR(20)
'helpful' INT(11)
'nothelpful' INT(11)
'date' DATE

我正在运行以下 PHP 代码:

<?
/*
YYY
YNY
YNN
YYN
NNN
NYN
NNY
NYY
*/
/* DECLARE VARS */
$subject = $_GET['subject'];
$level = $_GET['lvl'];
$school = $_GET['school'];
include("connect.php");

if($subject!="" && $level!="" && $school!=""){
/* GET Notes that have x subject, y level, and z school */
$yyyq = mysql_query("SELECT * FROM noteshare_notes WHERE subject='$subject' AND level='$level' AND school='$school' ORDER BY helpful DESC LIMIT 30"); /* quote missed here */
while($row=mysql_fetch_array($yyyq)){
echo '<span id="topic">[<a href="list.php?subject='.$row['subject'].'&lvl='.$row['level'].'">'.$row['level'].' '.$row['subject'].'</a>]</span> <a href="note.php?id='.$row['id'].'">'.$row['title'].'</a> <span id="usersize"><i>[uploaded by <a href="profile.php?id='.$row['uploader'].'">'.$row['uploader'].'</a>]</i></span><br>'; }
//yyy
}

if($subject!="" && $level!="" && $school==""){
/* Get Notes from x Subject and X Level, regardless of school. */
$yynq = mysql_query("SELECT * FROM noteshare_notes WHERE subject='$subject' AND level='$level' ORDER BY helpful DESC LIMIT 30"); /* quote missed here */
while($row=mysql_fetch_array($yynq)){
echo '<span id="topic">[<a href="list.php?subject='.$row['subject'].'&lvl='.$row['level'].'">'.$row['level'].' '.$row['subject'].'</a>]</span> <a href="note.php?id='.$row['id'].'">'.$row['title'].'</a> <span id="usersize"><i>[uploaded by <a href="profile.php?id='.$row['uploader'].'">'.$row['uploader'].'</a>]</i></span><br>'; }
//yyn
}

if($subject!="" && $level=="" && $school==""){
/* Get Level before Getting Notes without School */
$ynnq = mysql_query("SELECT * FROM noteshare_notes WHERE subject='$subject' GROUP BY level");
echo "<center>";
while($row=mysql_fetch_array($ynnq)){
echo '<a href="list.php?lvl='.$row['level'].'&subject='.$row['subject'].'">'.$row['level'].'</a><br>'; }
//ynn 
}

if($subject!="" && $level=="" && $school!=""){
/* Get level based on school + subject */
$ynyq = mysql_query("SELECT * FROM noteshare_notes WHERE subject='$subject' AND school='$school' GROUP BY level");
while($row=mysql_fetch_array($ynyq)){
echo '<a href="list.php?lvl='.$row['level'].'&school='.$row['school'].'&subject='.$row['subject'].'">'.$row['level'].'</a><br>'; }
//yny
}

if($subject=="" && $level=="" && $school==""){
//Error - Nothing + Nothing + Nothing = Nothing
//nnn
}

if($subject=="" && $level=="" && $school!=""){
/* Get Subject First based on School, thus redirecting to previous ynn (reverse clause)*/
$nnyq = mysql_query("SELECT * FROM noteshare_notes WHERE school='$school' GROUP BY subject");
while($row=mysql_fetch_array($nnyq)){
echo '<a href="list.php?subject='.$row['subject'].'&school='.$row['school'].'">'.$row['subject'].'</a><br>'; }
//nny
}

if($subject=="" && $level!="" && $school!=""){
/* Get Subjects based on level + school */
$nyyq = mysql_query("SELECT * FROM noteshare_notes WHERE level='$level' AND school='$school' GROUP BY subject");
while($row=mysql_fetch_array($nyyq)){
echo '<a href="list.php?subject='.$row['subject'].'&lvl='.$row['level'].'&school='.$row['school'].'">'.$row['subject'].'</a><br>'; }
//nyy
}

if($subject=="" && $level!="" && $school==""){
/* Get Subject based on level */
$nynq = mysql_query("SELECT * FROM noteshare_notes WHERE level='$level' GROUP BY subject");
while($row=mysql_fetch_array($nyyq)){
echo '<a href="list.php?subject='.$row['subject'].'&lvl='.$row['level'].'">'.$row['subject'].'</a><br>'; }
//nyn
}
?>

抱歉,因为它聚集了评论和可能性,哈哈。

它不断地给我返回

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

错误,我不知道如何修复它,我尝试了很多,很多东西要修复,但没有任何效果。我认为这可能是由于多个 AND 或数据库中没有 30 行的事实

有人知道如何解决这个问题吗?任何答案都会非常有帮助:)

干杯!

最佳答案

尝试一下这两个。你在奇怪的地方有单引号。 $school 之后没有单引号,并且在这两种情况下 LIMIT 30 之后都有单引号。这些可能会导致 MySQL 错误,或者至少会导致选择意外的行。

$yyyq = mysql_query("SELECT * FROM noteshare_notes WHERE subject='$subject' AND level='$level' AND school='$school' ORDER BY helpful DESC LIMIT 30");

$yynq = mysql_query("SELECT * FROM noteshare_notes WHERE subject='$subject' AND level='$level' ORDER BY helpful DESC LIMIT 30");

关于php - MySQL 资源错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9349032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com