lbh2011 Posted January 12, 2013 Share Posted January 12, 2013 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! Link to comment https://forums.phpfreaks.com/topic/273080-help-with-an-if-statement/ Share on other sites More sharing options...
Backslider Posted January 12, 2013 Share Posted January 12, 2013 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 } ?> Link to comment https://forums.phpfreaks.com/topic/273080-help-with-an-if-statement/#findComment-1405249 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 } ?> Link to comment https://forums.phpfreaks.com/topic/273080-help-with-an-if-statement/#findComment-1405270 Share on other sites More sharing options...
cpd Posted January 13, 2013 Share Posted January 13, 2013 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. Link to comment https://forums.phpfreaks.com/topic/273080-help-with-an-if-statement/#findComment-1405326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.