conditionals...
Posted: Thu Feb 17, 2005 11:50 pm
i have this code
my idea is when the user is an administrator, he can view all the posts in the database, otherwise, the user can only view what he posted.can somebody out there advise me on what code to put here?
thanks.
pleigh
Code: Select all
<?
$id = $_SESSIONї'userID'];
$query = "SELECT status FROM users WHERE userID='$id'";
$result = @mysql_query($query);
if ($result)
{
//verify administrator
if ($rowї0] == 'administrator')
{
$query = "SELECT date, title, postID FROM posts ORDER BY date DESC";
$result = @mysql_query($query);
if ($result)
{
echo "<tr><td width=80%><table><tr><td>TOPIC</td></tr></table></td><td width=20%><table><tr><td>DATE</td></tr></table></td></tr>";
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
//$post = $rowї2];
echo "<tr><td width=80%><table><tr><td><a href="reportingview.php?pid={$rowї2]}" class="under">$rowї1]</td></tr></table></td><td width=20%><table><tr><td>$rowї0]</td></tr></table></td></tr>";
}
mysql_free_result($result);
}
else
{
echo 'system error!<br>'.mysql_error();
}
mysql_close();
}
//if not administrator
else
{
$query = "SELECT date, title, postID FROM posts WHERE userID='$id' ORDER BY date DESC";
$result = @mysql_query($query);
if ($result)
{
echo "<tr><td width=80%><table><tr><td>TOPIC</td></tr></table></td><td width=20%><table><tr><td>DATE</td></tr></table></td></tr>";
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
//$post = $rowї2];
echo "<tr><td width=80%><table><tr><td><a href="reportingview.php?pid={$rowї2]}" class="under">$rowї1]</td></tr></table></td><td width=20%><table><tr><td>$rowї0]</td></tr></table></td></tr>";
}
mysql_free_result($result);
}
else
{
echo 'system error!<br>'.mysql_error();
}
mysql_close();
}
}
?>thanks.
pleigh