Page 1 of 1

restrict viewing by status

Posted: Sun Feb 15, 2004 4:02 pm
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

Posted: Sun Feb 15, 2004 5:01 pm
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.

Re: restrict viewing by status

Posted: Sun Feb 15, 2004 5:10 pm
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>";

Posted: Mon Feb 16, 2004 9:14 am
by Infinity
your second suggestion is what im looking for however it does not work
so any other suggestions would be great

thanx

Posted: Mon Feb 16, 2004 9:20 am
by dethron
How your system recognize the power user?

You may have to change the if-clause, but the idea is there.

Posted: Mon Feb 16, 2004 9:55 am
by vigge89
also, when echoing arrays, {} should be used around them, etc:
echo "user: {$info['usr']}";

Posted: Mon Feb 16, 2004 12:59 pm
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

Posted: Mon Feb 16, 2004 1:11 pm
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

Posted: Mon Feb 16, 2004 1:18 pm
by McGruff
Nice signature infinity. Are you by any chance single?

I wouldn't complain if you chose to change it.

Posted: Mon Feb 16, 2004 2:07 pm
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: