我有一个页面,登录用户可以在其中看到不同链接的列表,但前提是链接与 MySQL 数据库中的条目匹配,如下所示:
<li>
<?php
require ("scripts/connect.php");
$query = mysql_query("SELECT * FROM files WHERE subject='consulting' AND active='1'");
$numrows = mysql_num_rows($query);
if ($numrows > 0)
echo "
<a class='atags' href=\"javascript:showonlyone('consulting', this)\">Consulting</a>";
if ($numrows == 0)
echo "";
?>
</li>
<li>
<?php
require ("scripts/connect.php");
$query = mysql_query("SELECT * FROM files WHERE subject='Projects' AND active='1'");
$numrows = mysql_num_rows($query);
if ($numrows > 0)
echo "<li><a class='atags' href=\"javascript:showonlyone('projects', this)\">Projects</a></li>";
if ($numrows == 0)
echo "";
?>
</li>
ETC...
但是,我刚刚意识到,如果 $username 在我的 session_start(); 在主持人字段中有 1 我想展示一些不同的东西。我怎样才能做到这一点?从理论上讲,我正在寻找的是这样的:
if ($username && $moderator == 1) {
echo "You can edit this.";
}
else
echo "<li>
<?php
require ("scripts/connect.php");
$query = mysql_query("SELECT * FROM files WHERE subject='art' AND active='1'");
$numrows = mysql_num_rows($query);
if ($numrows > 0)
echo "
<a class='atags' href=\"javascript:showonlyone('art', this)\">Art</a>";
if ($numrows == 0)
echo "";
?>
</li>
<li>
<?php
require ("scripts/connect.php");
$query = mysql_query("SELECT * FROM files WHERE subject='computer' AND active='1'");
$numrows = mysql_num_rows($query);
if ($numrows > 0)
echo "<li><a class='atags' href=\"javascript:showonlyone('computer', this)\">Computer</a></li>";
if ($numrows == 0)
echo "";
?>
</li>
<li>
<?php
require ("scripts/connect.php");
$query = mysql_query("SELECT * FROM files WHERE subject='critical reading' AND active='1'");
$numrows = mysql_num_rows($query);
if ($numrows > 0)
echo "<li><a class='atags' href=\"javascript:showonlyone('criticalreading', this)\">Critical Reading</a></li>";
if ($numrows == 0)
echo "";
?>
</li>
<li>
<?php
require ("scripts/connect.php");
$query = mysql_query("SELECT * FROM files WHERE subject='french' AND active='1'");
$numrows = mysql_num_rows($query);
if ($numrows > 0)
echo "<li><a class='atags' href=\"javascript:showonlyone('french', this)\">French</a></li>";
if ($numrows == 0)
echo "";
?>
</li>";
这可能吗?谢谢。