在显示数据库中的详细信息之前添加条件



我在页面中有一个按钮"查看联系人详细信息"。单击后,它将调用">contact_detail.php"(下面给出的代码)。

它首先检查:

  1. 如果登录用户发送的明确兴趣被正在检查其联系方式的用户
  2. 如果是,它会检查登录者查看了多少联系人号码在用户中

如果不接受明示兴趣,则会出错:"如果您已经向该会员发送了明示兴趣,并且他/她已经接受,则该会员只显示联系方式。如果您感兴趣,请向他/她发送明示兴趣。">

如果条件1为真,但如果登录用户已经查看了3个以上的联系人号码,则会错误为"您一天只能查看3个联系人">

文件/函数运行良好。我只想给这个添加一个条件

首先,检查用户是否是付费会员。如果是,则直接显示联系人号码,而不执行条件1。这意味着,显示以下内容以及条件2

<div class="modal-dialog yoyo-large">
.
.
.
<div>

如果用户不是付费会员,则在显示联系人号码之前,运行条件1和2。

要检查登录用户是否是付费会员,可以在"register"表中进行检查,字段为"status",其中值应为"Paid"select * from register where matri_id='$from_id' and status is equal to Paid

有人能帮我学语法吗?

谢谢!

<?php
require("../connect/report.php");
$mid=$_SESSION['mid'];
$from_id = isset($_REQUEST['toid']) ? $_REQUEST['toid']:0;   
$exp_sel=mysql_query("select * from register where matri_id='$from_id'");
$fet=mysql_fetch_array($exp_sel);                                    
$today=date('Y-m-d');                                                                           
$exp_sel=mysql_query("select * from expressinterest where ei_sender='$mid' and ei_receiver='$from_id' and receiver_response ='Accept'");
$num=mysql_num_rows($exp_sel);
if($num>0)
{
$cnt = "SELECT * FROM payments WHERE (pemail = '$mid' or pmatri_id='$mid')";
$cn = mysql_query($cnt);
$ncha = mysql_fetch_array($cn);
if($ncha['p_no_contacts']-$ncha['r_cnt']>0)
{
$ch_viewd=mysql_query("select count(id) as row from today_contact where who='$mid' and on_date='$today'");
$ch_fet=mysql_fetch_array($ch_viewd);
if($ch_fet['row']<3)
{
?>                      
<div class="modal-dialog yoyo-large">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
</button>
<h1 class="modal-title" id="myModalLabel" style="color:red;">Remaining Contacts (
<?php echo ($ncha['p_no_contacts']-$ncha['r_cnt']);?>) 
</h1>
</div>
<div class="modal-body">
<div class="col-sm-12 form-group">
<div class="col-sm-6" style="font-size:13px;">         
<table class="table table-hover table-striped">
<tr height="30">
<td width="80">
<strong>Matri ID : 
</strong>
</td> 
<td> 
<?php echo $fet['matri_id']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Name : 
</strong>
</td> 
<td> 
<?php echo $fet['username']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Address : 
</strong> 
</td> 
<td> 
<?php echo $fet['address']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Phone : 
</strong> 
</td> 
<td> 
<?php echo $fet['phone']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Mobile : 
</strong> 
</td> 
<td> 
<?php echo $fet['mobile']; ?>
</td>
</tr>
<tr height="30">
<td>
<strong>Email : 
</strong>
</td> 
<td> 
<?php echo $fet['email']; ?>
</td>
</tr>
</table>                               
</div>
</div>
<?php       
$chk1=$ncha['r_cnt'];
$inc1=$chk1+1;
$upda="update payments SET r_cnt='$inc1' where  (pemail='$mid' or pmatri_id='$mid')"; 
$up=mysql_query($upda) or die(mysql_error());
$ex=mysql_query("select id from today_contact where who='$mid' and whose='$from_id'");
if(mysql_num_rows($ex)==0)
{                                   
mysql_query("insert into  today_contact (who,whose,on_date) values ('$mid','$from_id',now())");
}
else
{                                       
mysql_query("update  today_contact set on_date=now() where who='$mid' and whose='$from_id'");   
}
?>
</div>
</div>
</div>
<?php
}                                           
else
{
?>
<div class="modal-dialog">  
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
</button>
<h1 class="modal-title" id="myModalLabel" style="color:red;">Today's limit is over
</h1>
</div>
<div class="form-group">
<div class="col-sm-12">
<br>
<br>
<h3>&nbsp;&nbsp;You are allowed to view only 3 contacts in a day
</h3>
<br>
<br>
</div>
</div>
</div>
</div>
<?php
}
}
else
{
?>
<div class="modal-dialog">  
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
</button>
<h1 class="modal-title" id="myModalLabel" style="color:red;">Membership Expired
</h1>
</div>
<div class="form-group">
<div class="col-sm-12">
<br>
<br>
<h3>&nbsp;&nbsp;Buy a Premium Membership to contact him right away.
</h3>
<br>
<br>
</div>
</div>
</div>
</div>
<?php                                           
}
?>
<?php           
}
else
{
?>
<div class="modal-dialog">  
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
</button>
<h1 class="modal-title" id="myModalLabel" style="color:red;">Express interest not accepted
</h1>
</div>
<div class="form-group">
<div class="col-sm-12">
<br>
<br>
<h3>&nbsp;&nbsp;This member only shows contact details, if you have already sent him/her express interest,
<br> &nbsp;&nbsp;and he/she has accepted it.
</h3>
<br>
<br>
</div>
<div class="col-sm-12">
<h3 style="color:red;">&nbsp;&nbsp;
<a target="_blank" href="exp_interest.php?ei=<?php echo $from_id; ?>">Please send him/her express interest if you are interested.
</a>
</h3>
</div>
</div>
</div>
</div>
<?php 
} 

所以您要求查询用户是否是付费会员?

$paidMember = false;
$checkPaidMember = mysql_query("select * from register where matri_id='$from_id' AND status = 'Paid'");
if(mysql_num_rows($checkPaidMember) > 0){
$paidMember = true;
}

只需将带有userId和所需状态的select发送到数据库即可。如果数据库返回一个数据集,则存在一个具有您所要求的id和状态的用户。

Trincot是对的,你不应该使用mysql_*函数,并注意你的安全漏洞。

这就是你要找的吗?

<?php
require("../connect/report.php");
$mid = $_SESSION['mid'];
$from_id = isset($_REQUEST['toid']) ? $_REQUEST['toid'] : 0;
$exp_sel = mysql_query("select * from register where matri_id='$from_id'");
$fet = mysql_fetch_array($exp_sel);
$today = date('Y-m-d');
$exp_sel = mysql_query("select * from expressinterest where ei_sender='$mid' and ei_receiver='$from_id' and receiver_response ='Accept'");
$num = mysql_num_rows($exp_sel);
$paidMember = false;
$checkPaidMember = mysql_query("select * from register where matri_id='$from_id' AND status = 'Paid'");
if(mysql_num_rows($checkPaidMember) > 0){
$paidMember = true;
}
if ($num > 0 || $paidMember === true) { // added OR in this place for to bypass the first condition if it is a paid member
$cnt = "SELECT * FROM payments WHERE (pemail = '$mid' or pmatri_id='$mid')";
$cn = mysql_query($cnt);
$ncha = mysql_fetch_array($cn);
if ($ncha['p_no_contacts'] - $ncha['r_cnt'] > 0) {
$ch_viewd = mysql_query("select count(id) as row from today_contact where who='$mid' and on_date='$today'");
$ch_fet = mysql_fetch_array($ch_viewd);
if ($ch_fet['row'] < 3 || $paidMember === true) { // added OR in this place to bypass the second condition if it is a paid member
?>                      
<div class="modal-dialog yoyo-large">
<div class="modal-content">

最新更新