douyi6290 2012-10-12 21:50
浏览 30
已采纳

Echo之后的MySQL中的Php Echo IF IF声明[关闭]

The last block of code is my issue. I want a user to be able to see a different style of link depending on what page they're on. The link would be an if else statement from the SQL table itself. Now the biggest issue is the fact that I'm already using an echo variable to pull the link so I'm not sure how to reinitiate an if else inside of the SQL table itself.

<?php   
    $result=mysql_query("SELECT * FROM navigation WHERE enabled='1');
            while ($row=
            mysql_fetch_array($result))
                {

                echo $row['link'];

                }
?>

What I would like to display is something along the lines of

<?php   
    $result=mysql_query("SELECT * FROM navigation WHERE enabled='1' AND permissions >'1'");
            while ($row=
            mysql_fetch_array($result))
                {

                echo $row['link'];

                }

My Variable for Enabled is 1, so that if the variable is set to 0 the page is then disabled. After this it searches for your user permissions using

if ($admin != null)//Is Guest
if ($admin->get_permissions()==3)//Is Admin
elseif ($admin->get_permissions()==2)//Is VIP User
elseif ($admin->get_permissions()==1)//Is Registered User

I want the link to only appear to a user based off of it's registration status, but my biggest problem lies here. I want my user to see the navigation in a certain manner depending on what page they are, but the SQL table is already being queried and is imported as a variable already, so how would I have it display along the lines of

<?php
if (stripos($_SERVER['REQUEST_URI'], 'index.php')){
     echo '<p><a href="index.php" class="active">Home</a></p>';
}
else{
     echo '<p><a href="index.php">Index</a></p>';//<-Note the removed class index in this link
}

Sorry if it's hard to understand what I'm saying; tried to word it to the best of my ability.

  • 写回答

1条回答 默认 最新

  • doubingling4706 2012-10-12 22:06
    关注

    Have you tried NOT combining the query and doing something along the lines of:

    <?php
        $result=mysql_query("SELECT * FROM navigation WHERE enabled='1'");
        if ($result){
            while ($row=mysql_fetch_array($result)) {
                switch($row['permission']){
                    //obv not real html tags!!!
                    case 1: echo "<reg>".$row['link']."</reg>"; break; 
                    case 2: echo "<vip>".$row['link']."</vip>"; break; 
                    case 3: echo "<admin>".$row['link']."</admin>"; break;
                    default: echo "<blank>no link</blank>"; break;
                }
            }
        }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记