【发布时间】:2013-02-14 00:29:00
【问题描述】:
我试图找到一种显示 div 的方法,上面写着“将此用户添加到您的收藏夹”,但我只希望在用户的收藏夹少于 13 个时显示。所以一旦他们有 13 个收藏夹,div1 就会隐藏,而 div 2 就会显示出来。
我目前正在将我的 div 显示在与用户收藏夹不同的页面上:
<?php
$account_type = account_type();
while ($acctype = mysql_fetch_array($account_type))
if ($profile_id == $_SESSION['user_id']) {
}else{
if ($acctype['account_type'] == 'User') {
echo "<div class=\"infobox-profile\"><strong>Add to Favourites ".$profile[2]."</strong> - to add or remove this user to your favourites <a href=\"add_favorutie.php?to=".$profile_id."\">click here</a>";
echo "<div class=\"infobox-fav-close\"></div></div>";
}}
?>
然后在另一个页面上我回显出用户的最爱:
<?php
$favourites_set = get_favourites();
$fav_count = mysql_num_rows($favourites_set);
while ($fav = mysql_fetch_array($favourites_set)) {
echo "<a href=\"profile.php?id={$fav['fav_id']}\"><img width=\"60px\" height=\"60px\" class=\"fav_pic\" src=\"data/photos/{$fav['duo_id']}/_default.jpg\" /></a>";
}
所以我想要的是,当“收藏夹”集回显了 13 个收藏夹时,询问用户是否要添加更多收藏夹的 div 消失并回显另一个 div,例如“超出用户收藏夹”
我尝试过以下操作,但我是 php 新手,真的需要帮助,请有人告诉我我需要做什么。
<? if(mysql_num_rows($favourites_set) < 13) {
while ($fav = mysql_fetch_array($favourites_set)) {
$account_type = account_type();
if ($acctype['account_type'] == 'User') {
if ($profile_id == $_SESSION['user_id']) {
echo "favourites exceeded";
}else{
if ($acctype['account_type'] == 'User') {
echo "<div class=\"infobox-profile\"><strong>add favourites ".$profile[2]."</strong> - to add or remove this user to your favourites <a href=\"add_favourites.php?to=".$profile_id."\">click here</a>";
echo "<div class=\"infobox-fav-close\"></div></div>";
}}
【问题讨论】:
-
Please, don't use
mysql_*functions in new code。它们不再维护and are officially deprecated。看到red box?改为了解 prepared statements,并使用 PDO 或 MySQLi - this article 将帮助您决定哪个。 -
@njk +1 链接tastic(也是最正确的)评论