我的数据库中有逗号分隔的列。该列称为“访问”,它处理诸如1,2,3,4,5,6,7之类的数字。我需要比较会话值的要求称为kt_department,其中之一是逗号分隔的值,例如kt_department的值是4,那么其余数据将显示在页面中。但是,如果不是,它将继续到下一行,但是如果再次找不到,则应该继续到下一行,直到找到用逗号分隔的值为止。但是,如果他们什么也没找到,则会出现类似“无可用记录”的消息。并且发现的记录也应该计数。
我试图使自己的体重变大。
<?php
$news_connect = mysqli_connect("localhost","root","pwd", "dbase");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$kt_dept = $_SESSION['kt_department'] . " ";
$accessrights = explode(',', $row_news['accessrights']);
$news_query = "SELECT * FROM memo
WHERE (access LIKE '%{$accessrights}%' AND status='1' AND idcategory='1')";
$news_result = mysqli_query($news_connect, $news_query);
$row_news = mysqli_fetch_array($news_result);
echo $kt_dept;
?>
<div style="margin-top:30px;">
<table width="98%" border="0" cellspacing="5" cellpadding="0" class="curveborderboxnobg">
<tr>
<td height="70" colspan="2" class="brandtitle" style="padding-left:20px;line-height:60px; font-size:18px;"><img src="images/icons/news-announcement.png" width="20" height="20" style="margin-right:10px;"><strong>News and Announcement </strong></td>
</tr>
<tr>
<td height="40" colspan="2" style=" padding:0px 20px 0 20px;">
<table width="95%" border="0" style="margin-left:45px;" class="bortopbot" cellpadding="0" cellspacing="5">
<tr>
<td height="30" class="tabledetails" style="padding-top:20px;" ><strong><a href="news_bulletin.php?idmemonewsbulletin=<?php echo $row_news['idmemo']; ?>" class="lightbox" data-width="800" data-height="500"><?php echo $row_news['title']; ?></a></strong></td>
</tr>
<tr>
<td class="tabledetails" style="padding-bottom:20px;"><span style="font-size:12px;"><?php echo $row_news['shortdesc']; ?></span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="40" class="tabledetails" style="padding-left:10px;"> </td>
<td class="tabledetails" style="padding-right:20px; ">
<table width="263" border="0" align="right" class="tabledetails">
<tr>
<td align="center"><div align="right"><a href="news_bulletin_list.php?newsbul=<?php echo $row_news['idcategory']; ?>"><strong>View All </strong></a></div></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<table width="98%" border="0" cellspacing="5" style="margin-top:30px; " cellpadding="0" class="curveborderboxnobg">
<tr>
<td height="70" class="brandtitle" style="padding-left:20px;line-height:60px; font-size:18px;"><img src="images/icons/news-announcement.png" width="20" height="20" style="margin-right:10px;"><strong>News and Announcement </strong></td>
</tr>
<tr>
<td height="40" class="bortopbot" style=" padding:0px 20px 0 20px;">
<div align="center">- No News and Announcement - </div></td>
</tr>
</table>
<?php mysqli_close($news_connect); ?>
感谢大伙们。请帮我。谢谢!
最佳答案
要为您的问题提供实际答案(请注意Sharma):
从问题中摆脱掉用户名和密码进入数据库。即使它是本地主机,也伤害了我的眼睛。
回答您的问题。我会不建议您使用列access
和kt_dept
或您想调用的列创建第二个表。这样,您可以将访问整数与kt_dept连接-意味着一个kt_dept
具有零到多个access
。
有了这种实现,您只需要运行如下查询
SELECT kt_dept从newTable中访问='{$ access}'
并检查是否返回任何行。