Jump to content

Help with an IF statement...


lbh2011

Recommended Posts

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

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
}
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.