lbh2011 Posted January 12, 2013 Share Posted January 12, 2013 (edited) Hi, I've purchased a login script which uses this line to check if the user is an administrator and if so displays a link... <?=($c->is_admin == 'Yes')?'<a href="add.php">Add entry</a>':'<br>'?> My question is, how do I apply this to the following (which is on the same page), where I want to prevent the update and delete links from being visible? I have tried to do it like the example above but receive an error which states that the $row variable is undefined when I do... $row = '<tr> <td>'.$date_added.'</a></td> <td>'.$title.'</a></td> <td><a href="view.php?id='.$id.'">View Details</a></td> <td><a href="update.php?id='.$id.'">Update</a></td> <td><a href="delete.php?id='.$id.'">Delete</a></td> </tr>'; Also, how do I change the admin line to an IF statement e.g. if $c = is_admin {...} else {...} Thanks! Edited January 12, 2013 by lbh2011 Quote Link to comment Share on other sites More sharing options...
Backslider Posted January 12, 2013 Share Posted January 12, 2013 (edited) For the $row, simply use: <?php echo ($c->is_admin == 'Yes')?$row:''); ?> For the second: <?php if($c->is_admin == 'Yes') { // do stuff } else { // do something else } ?> Edited January 12, 2013 by Backslider Quote Link to comment Share on other sites More sharing options...
lbh2011 Posted January 13, 2013 Author Share Posted January 13, 2013 Thanks Backslider. How about within $row though? <td><a href="update.php?id='.$id.'">Update</a></td> How would I apply this code to that? (So only display the update link when the user is logged in) <?php if($c->is_admin == 'Yes') { // do stuff } else { // do something else } ?> Quote Link to comment Share on other sites More sharing options...
cpd Posted January 13, 2013 Share Posted January 13, 2013 (edited) Consider "building" the string instead of writing it all in one go. $row = '<tr> <td>'.$date_added.'</a></td> <td>'.$title.'</a></td> <td><a href="view.php?id='.$id.'">View Details</a></td>'; if($c->is_admin == 'Yes') { $row.= '<td><a href="update.php?id='.$id.'">Update</a></td>'; } $row.= '<td><a href="delete.php?id='.$id.'">Delete</a></td></tr>'; The $row.= means append to the variable. Edited January 13, 2013 by cpd Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.