PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pleigh
Forum Contributor
Posts: 445 Joined: Wed Jan 19, 2005 4:26 am
Post
by pleigh » Sun Mar 06, 2005 10:07 pm
i have a comment form in my page, here i limit the appearance of comment form to administrator status only.....now my problem is, if i am an administrator, i have the right to comment the message, i already done this, but i don't want the comment form to appear if i am viewing my own message/thread....here's my code below...
Code: Select all
<?
$uid = $_SESSIONї'userID'];
$query = "SELECT status FROM users WHERE firstname='$fn' and status='administrator'";
$result = @mysql_query($query);
if (mysql_num_rows($result) != 0)
{
$query = "SELECT userID FROM users WHERE userID='$uid'";
$result = @mysql_query($query);
if (!$result)
{
include('commentform.php');
}
else
{
NULL;
}
}
else
{
NULL;
}
?>
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Sun Mar 06, 2005 10:10 pm
just add something to your select to exclude the poster:
Code: Select all
"SELECT status FROM users WHERE firstname='$fn' and status='administrator' and posterid <> ".$_SESSIONї'id'];
pleigh
Forum Contributor
Posts: 445 Joined: Wed Jan 19, 2005 4:26 am
Post
by pleigh » Sun Mar 06, 2005 10:15 pm
i did this
Code: Select all
$query = "SELECT status FROM users WHERE firstname='$fn' and status='administrator' AND postID <>".$_SESSIONї'userID'];
it returned an error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\mysample\reportviewbodycontent.php on line 98
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Sun Mar 06, 2005 10:21 pm
instead of looking for a row count, just use mysql_fetch_assoc in your if. If there are no results, it will die.
example:
Code: Select all
<?
$uid = $_SESSIONї'userID'];
$query = "SELECT status FROM users WHERE firstname='$fn' and status='administrator'";
$result = @mysql_query($query);
if (mysql_fetch_assoc($result))
{
$query = "SELECT userID FROM users WHERE userID='$uid'";
$result = @mysql_query($query);
if (!$result)
{
include('commentform.php');
}
else
{
NULL;
}
}
else
{
NULL;
}
?>
pleigh
Forum Contributor
Posts: 445 Joined: Wed Jan 19, 2005 4:26 am
Post
by pleigh » Sun Mar 06, 2005 10:25 pm
problem still there....i still can see the comment box if viewing my own thread....
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 07, 2005 12:29 am
there's an error in the sql syntax.. mysql_error()