2013-02-13 29 views
0

即時通訊設法找到一種方式顯示一個div說「將此用戶添加到您的收藏夾」,但我只希望這顯示,如果用戶少於13收藏夾。所以只要他們有13個最喜歡的div1將隱藏和div 2將顯示。如果用戶收藏夾爲13或更少,則回顯div 1否則回顯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,詢問用戶是否想添加更多的收藏夾disapears並回顯另一個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>"; 
}} 
+2

[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。 – Kermit 2013-02-13 16:25:16

+0

@njk +1爲linktastic(和最正確的)評論 – jammypeach 2013-02-13 16:26:18

回答

0

一個簡單的方法來做到這一點是保持多少重複你的循環已經使用計數變量完成計數,並用它來測試反對。

例子:

$count=1; 

while ($fav = mysql_fetch_array($favourites_set)) 
{ 
    if ($count<13) 
    { 
     //loop has not yet iterated 13 times 
     //do stuff 
    } 
    else 
    { 
     //this loop has iterated 13 times or more. do other stuff. 
     //echo out your 'user favourites exceeded' div 
     //and optionally, break the loop to prevent repetition. 
     break; 
    } 
    $count++; //increment the loop counter 
} 

編輯:我不會打壞你的腦袋,但使用mysqliPDO,不mysql - 看到你的細節問題的評論。

相關問題