我一直在编写一些代码,根据教师上传的与同事和学生分享的项目数量向他们授予徽章。
当数组为空时,我遇到了问题。什么都没有出现。
我尝试了一个 empty() 函数,但我一定把它放在了错误的位置,因为它开始出现在有上传的用户身上。
所以基本上在下面的代码中,我遇到困难的是“如果 $uploads < 1”部分。
..由此产生的问题是如何在 mysql_fetch_array($upload_count) 为空的地方得到一条回显消息?
<?php
$total_uploads = mysql_query("SELECT members.member_id, members.member_firstname, members.member_lastname, COUNT(*)
FROM uploads
JOIN members
ON uploads.member_id = members.member_id
GROUP BY uploads.member_id ");
$total_uploads_count = @mysql_num_rows($total_uploads);
$upload_count = mysql_query("SELECT members.member_id, members.member_firstname, members.member_lastname, COUNT(*)
FROM uploads
JOIN members
ON uploads.member_id = members.member_id AND members.member_id = ". $_SESSION['member_id'] . "
GROUP BY uploads.member_id ");
while($row_count=mysql_fetch_array($upload_count))
{
$uploads = $row_count['COUNT(*)'];
$unlock2 = 5 - $row_count['COUNT(*)'] ;
$unlock3 = 20 - $row_count['COUNT(*)'] ;
$unlock4 = 50 - $row_count['COUNT(*)'] ;
$unlock5 = 100 - $row_count['COUNT(*)'] ;
$unlock6 = 200 - $row_count['COUNT(*)'] ;
echo " you have <span class =\"blue_inherit\"> $uploads </span> uploads.<br/><br/>";
if ($uploads < 1 )
{
echo "Upload a resource to share in order to unlock your novice uploader badge!<br/>
<img src=\"images/badges/badge_e_share_1_locked.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" />";
}
else if ($uploads >= 1 && ($uploads < 5 ))
{
echo "Well done, you've unlocked your novice sharer's badge. <br/>
<img src=\"images/badges/badge_e_share_1.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/>
If you upload $unlock2 more resources, you can unlock your E-sharing advanced beginner's badge. <br/>
<img src=\"images/badges/badge_e_share_2_locked.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/>
";
}
else if ($uploads >= 5 && ($uploads < 20 ))
{
echo "Well done, you've unlocked your E-sharing advanced beginner's badge. <br/>
<img src=\"images/badges/badge_e_share_2.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/>
If you upload $unlock3 more resources, you can unlock your E-sharing mini-hero badge. <br/>
<img src=\"images/badges/badge_e_share_3_locked.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/> ";
}
else if ($uploads >= 20 && ($uploads < 50 ))
{
echo "Well done, you've unlocked your E-sharing mini-hero badge. <br/>
<img src=\"images/badges/badge_e_share_3.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/>
If you upload $unlock4 more resources, you can unlock your E-sharing hero badge. <br/>
<img src=\"images/badges/badge_e_share_4_locked.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/> ";
}
else if ($uploads >= 50 && ($uploads < 100 ))
{
echo "Well done, you've unlocked your E-sharing hero badge. <br/>
<img src=\"images/badges/badge_e_share_4.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/>
If you upload $unlock5 more resources, you can unlock your E-sharing super-hero badge. <br/>
<img src=\"images/badges/badge_e_share_5_locked.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/> ";
}
else if ($uploads >= 100 && ($uploads < 200 ))
{
echo "Well done, you've unlocked your E-sharing super-hero badge. <br/>
<img src=\"images/badges/badge_e_share_5.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/>
If you upload $unlock6 more resources, you can unlock your E-sharing Guru badge. <br/>
<img src=\"images/badges/badge_e_share_6_locked.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/> ";
}
else
{
echo "You've now a Guru!! <br/>
<img src=\"images/badges/badge_e_share_6.png\" width=\"200\" height=\"200\" alt=\"Sharing Badge\" /><br/> ";
}
}
?>