2uzhan.com
Advertisement
Now Place:2uzhan.com » if .....else statement syntax

if .....else statement syntax

PHP @ January 4, 2005   Views:0

Hi I'm new to php and trying to figure this problem out.
I have this snippet of code that shows a hyperlink 'view' if the account is active(i.e =1) in a table

<a href="<?php if (($x_ActiveAcc == 1)) { echo "Apartmentview.php?key=" . urlencode($sKey); } else { echo "javascript:alert('Invalid Record! Key is null');"; } ?>">View</a>

what I want to do is that if $x_ActiveAcc is =0 that no hyperlink is dispalyed and the space will be blank.
i.e all $x_ActiveAcc =1 displays a hyperlink ..'view'
and all $x_ActiveAcc =1 will be blank.
Also how do I replace the hyperlink word 'view' in the code with an image instead.
Thanks in advance.
Miriam Haden

--------------Solutions-------------

...i.e.

I'm guessing it should be:

So what you do is something like:

PHP Code:

<?php 
if (($x_ActiveAcc == 1)) {
    echo "<a href=\"Apartmentview.php?key=".urlencode($sKey)."\"><img src=\"whatever_image.jpg\"></a>"; 

else{//the $_ActiveAcc is 0 or whatever else other than 1
    echo "blank";//or whatever you want to do
}

Thanks very much bodzan that worked like a charm:-)
heres formatting for the image as well if anyone else interested.

<img src=\"images/yourimage.gif \"border=\"0\"width=\"20\"height=\"20\"align=\"top\"alt=\"Details\">
thanks again

Tags:
© 2018 2uzhan.com Contact