restrict viewing by status

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

Post Reply
Infinity
Forum Commoner
Posts: 44
Joined: Mon Feb 02, 2004 12:48 pm

restrict viewing by status

Post by Infinity »

i have a table set up wich gets data from mysql database it has 5 columns and i want to restrict viewing of the 5th column only to certain users ive created a goup called power user how can i let everyone view the 1st 4 columns and power user to view all 5 here is part of the code

Code: Select all

$query = "SELECT * FROM uk_numberones  WHERE `year` = '$year'"; 
   $result = mysql_query($query); 
   $numrows = mysql_num_rows($result); 




echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 
echo "<tr>"; 
echo "<td width='100%' background='./templates/fisubsilversh/images/cellpic3.gif'><div align='center' class='style2 style3'><strong> 
          Number 1 Singles from $year </strong></div></td>"; 
echo "</tr>"; 
echo "</table>"; 
echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 




echo "<td width='13%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Date</div></td>"; 
echo "<td width='33%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Artist</div></td>"; 
echo "<td width='39%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Title</div></td>"; 
echo "<td width='6%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Wks</div></td>"; 
//echo "<td width='9%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Download</div></td>";    

    
   while($row = mysql_fetch_array($result)) 



{ 
      echo "<tr><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[date]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[artist]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[title]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[wks1]</div></td></tc>"; 
 	  
	  //echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'><a href="$row[dllink]"><img src='./templates/fisubsilversh/images/icon_download.gif'></a></div></td></tr>"; 
}





echo "</table>";
the columns i want to restrict are comented out
thanks
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

There are many ways. :)

First of all, change the query just like that

Code: Select all

<?php
if($user=="poweruser")
    $sql = "SELECT * FROM uk_numberones  WHERE `year` = '$year'"; 
else
    $sql = "SELECT date,artist,title,wks1 FROM uk_numberones  WHERE `year` = '$year'";
?>
Or you can put an if-else statement to the last row(that is commented out.) of your table.

Good Luck.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Re: restrict viewing by status

Post by dethron »

As you mentioned above, this is another way.

Code: Select all

$query = "SELECT * FROM uk_numberones  WHERE `year` = '$year'"; 
   $result = mysql_query($query); 
   $numrows = mysql_num_rows($result); 




echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 
echo "<tr>"; 
echo "<td width='100%' background='./templates/fisubsilversh/images/cellpic3.gif'><div align='center' class='style2 style3'><strong> 
          Number 1 Singles from $year </strong></div></td>"; 
echo "</tr>"; 
echo "</table>"; 
echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 




     echo "<td width='13%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Date</div></td>"; 
     echo "<td width='33%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Artist</div></td>"; 
     echo "<td width='39%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Title</div></td>"; 
     echo "<td width='6%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Wks</div></td>"; 
if($user=="poweruser")
     echo "<td width='9%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Download</div></td>";    

    
   while($row = mysql_fetch_array($result)) 



{ 
      echo "<tr><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[date]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[artist]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[title]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[wks1]</div></td></tc>"; 
 	  
           if($user=="poweruser")
	  echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'><a href="$row[dllink]"><img src='./templates/fisubsilversh/images/icon_download.gif'></a></div></td></tr>"; 
}

echo "</table>";
Infinity
Forum Commoner
Posts: 44
Joined: Mon Feb 02, 2004 12:48 pm

Post by Infinity »

your second suggestion is what im looking for however it does not work
so any other suggestions would be great

thanx
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

How your system recognize the power user?

You may have to change the if-clause, but the idea is there.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

also, when echoing arrays, {} should be used around them, etc:
echo "user: {$info['usr']}";
Infinity
Forum Commoner
Posts: 44
Joined: Mon Feb 02, 2004 12:48 pm

Post by Infinity »

thanx
I don't want to echo the array I just need to find the value or to be more precise check the value

ok ive set up a new rank in phpbb called club member
and using

Code: Select all

<?php
echo " rank ",$userdata[user_rank];
?>
returns me the value 8 so i know that i need to use something like

Code: Select all

<?php
if($user_rank=='8')
?>
or should it be

Code: Select all

<?php
if($user_data['user_rank']==8)

?>
what would be the correct format for the if statement
thanx
Infinity
Forum Commoner
Posts: 44
Joined: Mon Feb 02, 2004 12:48 pm

Post by Infinity »

ok I tried this

Code: Select all

<?php
if($userdata['user_rank']==8)
?>
and it seems to work ok
if ive made any mistakes please point them out
i'm new to php as u can prob tell
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Nice signature infinity. Are you by any chance single?

I wouldn't complain if you chose to change it.
Infinity
Forum Commoner
Posts: 44
Joined: Mon Feb 02, 2004 12:48 pm

Post by Infinity »

lol no McGruff Unfortunately not lol no i dont mean that shes great she'd be even better if she knew php lol :lol:
Post Reply