0

嗨,我的网站上有一个基本的点赞系统。基本上一旦用户点击喜欢,这会将 user_id-has_liked 从 0 设置为 1。

如果他们的 user_id_has_liked 设置为 0,则显示类似链接,如果设置为 1,则显示不同。但是我想添加另一个条件,如果结果不在 mysql 中,则回显类似的链接。

有人可以告诉我在哪里以及我会添加什么来实现这一点。

<div class="profile_likes">
<?php
$user_like_set = user_like_status();
while ($like = mysql_fetch_array($user_like_set)) 
if ($like['user_id_has_liked'] == '0')  { ?>

<a href="like_profile.php?to=<?php echo "$profile_id"; ?>">Like</a>&nbsp;&nbsp;|&nbsp;&nbsp;<?

$count_likes_set = count_likes();
while ($likes = mysql_fetch_array($count_likes_set)) {

    echo "". $likes['likes'] ." People Like ".$profile[2]."";

    //$check_new_duos_set = check_new_escort_duos(); while ($newd = mysql_fetch_array($check_new_duos_set)) { 

    ?>

    <? } }?>



    <?php
$user_like_set = user_like_status();
while ($like = mysql_fetch_array($user_like_set)) 
if ($like['user_id_has_liked'] == '1')  { ?>

<a href="unlike_profile.php?to=<?php echo "$profile_id"; ?>">Unlike</a>&nbsp;&nbsp;|&nbsp;&nbsp;<?

$count_likes_set = count_likes();
while ($likes = mysql_fetch_array($count_likes_set)) {

    echo "". $likes['likes'] ." People Like ".$profile[2]."";

    //$check_new_duos_set = check_new_escort_duos(); while ($newd = mysql_fetch_array($check_new_duos_set)) { 
    ?>

    <? } }?>
    </div>
4

3 回答 3

0

try this i just made one change that your user_like_status(); should return true or false

<div class="profile_likes">
<?php
    $user_like_set = user_like_status();//should return true or false
    if ($user_like_set == false){
        $what = "Like"; 
    }else{
        $what = "Unlike";
    }?>    
    <a href="like_profile.php?to=<?php echo "$profile_id"; ?>"><?php echo $what ;?></a>&nbsp;&nbsp;|&nbsp;&nbsp;
    <?php 
    $count_likes_set = count_likes();
    while ($likes = mysql_fetch_array($count_likes_set)) {
    echo "". $likes['likes'] ." People Like ".$profile[2]."";
    }
 ?>
</div>
于 2013-02-10T15:31:52.783 回答
0

尝试在使用 echo/print 函数时保持一致性,并通过终止 php 标签来模拟它们,你的代码会变得更加清晰。

<?php
    function printLikeLink($likeLink){
          echo "<a href='{$likeLink}'>Like this profile</a>";
    }
    $user_like_set = user_like_status();
    if ($like = mysql_fetch_array($user_like_set)){
        if ($like['user_id_has_liked'] == '1')  {
            echo "<a href=\"unlike_profile.php?to={$profile_id}\">Unlike</a>|";
            $count_likes_set = count_likes();
            while ($likes = mysql_fetch_array($count_likes_set)) {
                echo "". $likes['likes'] ." People Like ".$profile[2]."";
                //$check_new_duos_set = check_new_escort_duos(); while ($newd = mysql_fetch_array($check_new_duos_set)) { 
            }
        }else printLikeLink("like_profile.php?to={$profile_id}");
    }else printLikeLink("like_profile.php?to={$profile_id}"); // Edit this link.
?>
于 2013-02-10T14:31:23.023 回答
0

您应该尝试mysql_num_rows。它将为您提供记录集中存在的行数。除此之外,请注意,您使用的 API 已弃用。在 mysql 网站上寻找建议的替代方案。

于 2013-02-10T14:32:01.513 回答