显示基于 2 个表的 MYSQL 结果的特定图像。选择,PHP
我正在尝试根据存储在 2 个 MYSQL 表中的内容创建一个用户评级系统。
一张表称为“图像标记”,其他表称为“标记”。
我想检查“authorid”行,该行在两个表中都是相同的,它存储基于用户“authorid”的数字。
我想根据在“markers”和“imagemarkers”表中的“authorid”中找到特定用户 ID 号的次数来显示特定图像。
这是在页面顶部声明的:
$theID = $_GET['id'];
到目前为止我的代码是:
<? $img0 = "<img src='../webimages/0star.png'>";
$img1 = "<img src='../webimages/1star.png'>";
$img2 = "<img src='../webimages/2star.png'>";
$img3 = "<img src='../webimages/3star.png'>";
$img4 = "<img src='../webimages/4star.png'>";
$img5 = "<img src='../webimages/5star.png'>"; ?>
<? $result3 = mysql_query("SELECT * FROM `markers`, `imagemarkers` WHERE authorid = $theID");
$rows = mysql_num_rows($result3); ?>
<?php
while($row = mysql_fetch_array($result3)){
if ($result3 > 1) {
echo "$img1";
} elseif ($result3 == 5) {
echo "$img2";
} elseif ($result3 == 10) {
echo "$img3";
} elseif ($result3 == 20) {
echo "$img4";
} elseif ($result3 == 30) {
echo "$img5";
} else {
echo "$img0";
}
?>
<? } ?>
我的 mysql 表行“authorid”存储为 INT,11,并勾选允许 null。
我收到的错误是:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource....
请帮我解决这个问题。 非常感谢您抽出时间。
更新,这是我的新代码,它仍然显示“$img0”,而它应该显示“$img3”:
<? $img0 = "<img src='../webimages/0star.png'>";
$img1 = "<img src='../webimages/1star.png'>";
$img2 = "<img src='../webimages/2star.png'>";
$img3 = "<img src='../webimages/3star.png'>";
$img4 = "<img src='../webimages/4star.png'>";
$img5 = "<img src='../webimages/5star.png'>"; ?>
<? $row[0] = mysql_query("SELECT * FROM `markers`, `imagemarkers` WHERE authorid = '". (int)$theID."'");
if ($row[0] > 1) {
echo "$img1";
} elseif ($row[0] > 5) {
echo "$img2";
} elseif ($row[0] > 10) {
echo "$img3";
} elseif ($row[0] > 20) {
echo "$img4";
} elseif ($row[0] > 30) {
echo "$img5";
} else {
echo "$img0";
}
?>
我正在计算特定用户编号在“authorid”行中显示并匹配“theID”的位置,来自表“imagemarkers”和“markers”。用户将其他数据存储在数据库中,并通过存储这些数据,根据他们填写的存储信息的表单填充“markers”和“imagemarkers”中的“authorid”行。
我希望这可以帮助您理解我正在尝试做什么。
I am trying to create a user rating system based on the content stored in 2 MYSQL tables.
One table is called "imagemarkers", and the other "markers".
I want to check the row "authorid", which is the same in both tables, which stores a number based on the 'authorid' of the user.
I want to show a particular image based on the number of times that specific user id number is found in "authorid" from both tables "markers" and "imagemarkers".
this is declared at the top of the page:
$theID = $_GET['id'];
The code i have so far is:
<? $img0 = "<img src='../webimages/0star.png'>";
$img1 = "<img src='../webimages/1star.png'>";
$img2 = "<img src='../webimages/2star.png'>";
$img3 = "<img src='../webimages/3star.png'>";
$img4 = "<img src='../webimages/4star.png'>";
$img5 = "<img src='../webimages/5star.png'>"; ?>
<? $result3 = mysql_query("SELECT * FROM `markers`, `imagemarkers` WHERE authorid = $theID");
$rows = mysql_num_rows($result3); ?>
<?php
while($row = mysql_fetch_array($result3)){
if ($result3 > 1) {
echo "$img1";
} elseif ($result3 == 5) {
echo "$img2";
} elseif ($result3 == 10) {
echo "$img3";
} elseif ($result3 == 20) {
echo "$img4";
} elseif ($result3 == 30) {
echo "$img5";
} else {
echo "$img0";
}
?>
<? } ?>
My mysql table row "authorid" is stored as INT, 11, and allow null ticked.
The error im getting is:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource....
Please help me solve this.
Thank you very much for your time.
Update, This is the new code i have, and it is still displaying '$img0', when it should be showing '$img3':
<? $img0 = "<img src='../webimages/0star.png'>";
$img1 = "<img src='../webimages/1star.png'>";
$img2 = "<img src='../webimages/2star.png'>";
$img3 = "<img src='../webimages/3star.png'>";
$img4 = "<img src='../webimages/4star.png'>";
$img5 = "<img src='../webimages/5star.png'>"; ?>
<? $row[0] = mysql_query("SELECT * FROM `markers`, `imagemarkers` WHERE authorid = '". (int)$theID."'");
if ($row[0] > 1) {
echo "$img1";
} elseif ($row[0] > 5) {
echo "$img2";
} elseif ($row[0] > 10) {
echo "$img3";
} elseif ($row[0] > 20) {
echo "$img4";
} elseif ($row[0] > 30) {
echo "$img5";
} else {
echo "$img0";
}
?>
I am counting where the specific user number shows and matches 'theID' in the 'authorid' row, from both tables 'imagemarkers' and 'markers'. The user is storing other data in the database, and by storing this fills the 'authorid' row in both 'markers' and 'imagemarkers' based on which form they fill in to store the info.
I hope this helps you understand what i am trying to do..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
$theID
周围添加单引号,同时确保 $theID 检查为整数或在其前面放置 (int):如果错误仍然发生,请替换为此,然后查看出现的错误:
因为那么
$result3
不是 mysql_num_rows 的有效结果资源add single quotes around
$theID
, also make sure $theID is checked as an integer or place (int) in front of it:if the error still occurs replace with this, and see what error you get:
Because then
$result3
is no valid result resource for mysql_num_rows首先,如果两个表中都存在“authorid”行,则应在查询中指定您指的是哪一个:
其次,在“while”循环内的所有位置将 $result3 替换为 $row[0]:
最后,有逻辑有问题。
你能解释一下完整的数据库结构吗,除了authorid之外还有哪些列?
First of all, if row 'authorid' exists in both tables, you should specify in queries, which one are you referring to:
Second, replace $result3 with $row[0] everywhere inside "while" loop:
And finally, there is something wrong with logic.
Can you explain complete DB-structure, what columns are there except authorid?