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!

Edited by lbh2011
Link to comment
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
}
?>

Link to comment
Share on other sites

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 by cpd
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.