Php 如果帐户类型=x,则转到链接1;如果帐户类型=y,则转到链接2?
我的网站上有两类用户,“免费”和“高级”。 基本上,我有一个消息系统,它列出消息和发送消息的用户 当您单击用户名/图像时,它将链接到Php 如果帐户类型=x,则转到链接1;如果帐户类型=y,则转到链接2?,php,mysql,hyperlink,Php,Mysql,Hyperlink,我的网站上有两类用户,“免费”和“高级”。 基本上,我有一个消息系统,它列出消息和发送消息的用户 当您单击用户名/图像时,它将链接到'profile.php?id=(user_id) 我想做的是,如果发送消息的用户的帐户类型为'free',那么我希望在单击时将用户转到另一个链接 我对php真的很陌生,不知道该怎么做,请有人给我举个例子,说明我是如何做到这一点的。这是我目前的密码 功能: function message_account_type() { global $c
'profile.php?id=(user_id)
我想做的是,如果发送消息的用户的帐户类型为'free',那么我希望在单击时将用户转到另一个链接
我对php真的很陌生,不知道该怎么做,请有人给我举个例子,说明我是如何做到这一点的。这是我目前的密码
功能:
function message_account_type() {
global $connection;
global $_SESSION;
global $profile_id;
global $message_id;
$query = "SELECT ptb_users.account_type, ptb_messages.from_user_id
FROM ptb_users, ptb_messages
WHERE ptb_messages.from_user_id = \"$profile_id\"
AND ptb_profiles.user_id = ptb_messages.from_user_id ";
$message_account_type = mysql_query($query, $connection);
confirm_query($query, $connection);
return $message_account_type;
}
php:
最好的办法是在
profile.php
中提供相关的模板文件。例如,在profile.php
上,可以执行以下操作:
$the_user = new User($_REQUEST['id']);
$include_file = ($the_user->account_type == 'free') ? 'free' : 'premium';
include($include_file.'-profile.php');
我真的不知道为什么你们中有这么多人打开和关闭
旁注:PHP是区分大小写的“自由”不等于“自由”
$the_user = new User($_REQUEST['id']);
$include_file = ($the_user->account_type == 'free') ? 'free' : 'premium';
include($include_file.'-profile.php');
<?php
function is_premium_user($profile_id)
{
$query = sprintf("SELECT ptb_users.account_type WHERE ptb_messages.from_user_id = '%s' AND account_type = 'Premium' LIMIT 1", $profile_id );
$result = mysql_query($query);
if (!mysql_fetch_assoc($result))
return false;
return true;
}
$message_account_type = message_account_type();
while ($type = mysql_fetch_array($message_account_type))
if (is_premium_user($profile_id))
echo '<a href="profile.php?id='.$inbox['from_user_id'].'><img width="50px" height="50px" src="data/photos/'.$inbox['from_user_id'].'/_default.jpg"/></a></div><div class="message_text"> <a href="profile.php?id='.$inbox['from_user_id'].'">'.$inbox['display_name'].'</a>';
else
echo '<a href="members.php?id='.$inbox['from_user_id'].'><img width="50px" height="50px" src="data/photos/'.$inbox['from_user_id'].'/_default.jpg"/></a></div><div class="message_text"> <a href="members.php?id='.$inbox['from_user_id'].'">'.$inbox['display_name'].'</a>';
?>