-1

尝试制作一个简单的网站,用户可以在其中拥有不同的帐户级别。例如,帐户类型为“a”和“b”的用户将在顶部看到一个链接/按钮,上面写着基本,而帐户类型为“c”的用户将看到一个链接/按钮,上面写着完整会员。

我有一个代码几乎可以满足我的需要,它将用户保存在数据库中不同的 A/B/C 类别中。

如上所述,我只需要知道我必须做什么才能显示指向不同帐户类型的不同链接?

另外,我知道下面的代码不是最好的代码,但只需要用我所拥有的来实现我现在所追求的结果。

<?php
session_start(); // Must start session first thing

// See if they are a logged in member by checking Session data
$toplinks = "";
if (isset($_SESSION['id'])) {
    // Put stored session variables into local php variable
    $userid = $_SESSION['id'];
    $username = $_SESSION['username'];
    $toplinks = '<a href="member_profile.php?id=' . $userid . '">' . $username . '</a> &bull; 
    <a href="member_account.php">Account</a> &bull; 
    <a href="logout.php">Log Out</a>';
} else {
    echo 'Please <a href="login.php">log in</a> to access your account';
    exit(); 
}
?>
<?php
//Connect to the database through our include 
include_once "scripts/connect_to_mysql.php";
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM members WHERE id='$userid'"); 
while($row = mysql_fetch_array($sql)){
$country = $row["country"];
$state = $row["state"];
$city = $row["city"];
$accounttype = $row["accounttype"]; 
$bio = $row["bio"]; 
}
// Give different options or display depending on which user type it is
if ($accounttype == "a") {
    $userOptions = "You get options for Expert User";
} else if ($accounttype == "b") {
    $userOptions = "You get options for Expert User";
} else if ($accounttype == "c") {
    $userOptions = "You get options for Expert User";
} else {
    $userOptions = "You get options for Super User";
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Member Account</title>
<link rel="stylesheet" type="text/css" href="style/style.css">
<style type="text/css">
<!--
body {
    margin: 0px;
    background-image: url(imgs/bgnoise.png);
    background-repeat: repeat;
}
-->
</style>

</head>
<body>
<?php include_once("temps/template_header.php");?>
<table style="background-image: url(imgs/horizontal_nav_bg.jpg);"  repeat="x" width="100%" border="0" cellpadding="0">
  <tr>
    <td height="94" ><table style=" margin-left:20px; " width="734" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="156"><p><a href="edit_info.php" target="_self"><img src="imgs/info.png" width="35" height="35" border="0" "/>Edit Information</a></p></td>
        <td width="179"><a href="edit_pic.php" target="_self"><img src="imgs/very.png" width="35" height="35" border="0" />Verify Your Identity</a></td>
        <td width="126"><a href="member_profile.php?id=<?php echo "$userid"; ?>" target="_self"><img src="imgs/profile.png" width="35" height="35" border="0" />View Profile</a></td>


        <td width="138"><img src="imgs/basket.png" width="35" height="35" /><a href="http://somesite.com">Buy Bitcoin</a></td>
        <td width="135"><img src="imgs/user.png" width="35" height="35" alt="user" /><?php echo "$username"; ?></td>
        </tr>
      </table>      <h1>&nbsp;</h1></td>
  </tr>
</table>

<table width="700" align="right" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><h3></h3></td>
  </tr>
</table>
<table width=950" cellpadding="3" cellspacing="3" style="line-height:1.5em;">
  <tr>
    <td width="118" valign="top" bgcolor="#E4E4E4"><h6>YOUR ACCOUNT<br />
        <a href="edit_info.php" target="_self">Edit Information </a><br />
        <a href="edit_pic.php" target="_self">Verify Your Identity</a><br />    
        <a href="member_profile.php?id=<?php echo "$userid"; ?>" target="_self">View Profile</a></h6>
      <h6><?php echo "$bio"; ?><br />
   </h6></td>
     <!-- See the more advanced member system tutorial to see how to place default placeholder pic until member uploads one -->
    <td width="160" valign="top"><div align="center"><img src="memberFiles/<?php echo "$userid"; ?>/pic1.jpg" alt="Ad" width="150" /></div></td>
    <td width="201" valign="top">
      Country: <?php echo "$country"; ?> <br />
      State: <?php echo "$state"; ?><br />
      City: <?php echo "$city"; ?>
      <table width="50" border="0" cellspacing="0" cellpadding="0">
        <tr>
        </tr>
      </table>      <br />
    </td>
    <td width="430" margin="left" style="margin-right:0px;" rowspan="2" valign="top"><div id="veri"><img src="imgs/verifynote.png" width="430" height="600" /> </div></td>
  </tr>
  <tr>
    <td colspan="3" valign="top"><br />
      <br />
    <br />
    <div style="overflow:hidden; width:100%px;">
  <iframe width="565" height="400"  scrolling="no" frameBorder="0"
  src="http://bitcoin.clarkmoody.com/widget/chart/" 
  style="width:728px; height:270px; border:none; margin-left:-60px;"/>  
</div>
    </td>
  </tr>
</table>


<?php include_once("temps/template_footer.php");?>
</body>
</html>`

请温柔一点,因为我是 PHP 新手,刚刚学习曲线。

谢谢

4

1 回答 1

0

我不确定我是否正确理解了这一点,但如果您想根据用户组显示不同的链接,只需执行以下操作:

if ($accounttype == "a") {
echo '<a href="">Page for user a</a>';
} 

else if ($accounttype == "b") {
    echo '<a href="">Page for user b</a>';

} else if ($accounttype == "c") {
    echo '<a href="">Page for user c</a>';
} else {
    echo '<a href="">Page for others</a>';
}

另外我建议你使用mysqli。它与mysql非常相似。http://php.net/manual/en/book.mysqli.php(Myqsl正在被移除)

于 2013-02-07T20:38:20.957 回答