Forums

PHP

This topic is locked

If fieldname='value' then 'value' else 'value'

Posted 01 Dec 2003 11:28:18
1
has voted
01 Dec 2003 11:28:18 Rene Bandsma posted:
How do I write a If, then, Else code in PHP?

If the fieldname has a specific value, the user must not see that value but another text.

I'm always using ASP, but in the new projectgroup I am sitting in, they only want to use PHP...

Please help a PHP newbie.

Replies

Replied 02 Dec 2003 03:20:15
02 Dec 2003 03:20:15 Nozomi Kugita replied:
If I just speak of the format of if statment, this is how it's written in PHP:

< ?php
if ($fieldName == "SpecificValue"{
echo $AnotherText;
}else {
echo $fieldName;
}
?>

Modify above code as you like.
- Noz
Replied 02 Dec 2003 16:58:10
02 Dec 2003 16:58:10 Greta Garberini replied:
With more than 2 or three "ifs" you can also use switch / case:

switch ($menu)
{
case 1:
echo "this is case1";
break;
case 2:
echo $soandso;
break;
case n:
....;
break;
default:
echo "none of the above";
}

hope it helps
Replied 03 Dec 2003 04:18:59
03 Dec 2003 04:18:59 Nozomi Kugita replied:
Yup, that works as well...
Replied 03 Dec 2003 10:41:14
03 Dec 2003 10:41:14 Rene Bandsma replied:
Works fine! I just created my first code in PHP <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Thanks to you i've written the following code:

<pre id=code><font face=courier size=2 id=code>&lt;?PHP
if ($row_edit['costumer_name']=='test') { print"&lt;a href='update.php?record_number=2'&gt;More detail...&lt;/a&gt;";} else { echo 'access denied';}
?&gt; </font id=code></pre id=code>

Now I want to make the record_numer=2 dynamic; and this will work:

<pre id=code><font face=courier size=2 id=code>&lt;a href="update.php?record_number=&lt;?php echo $row_edit['record_number'];?&gt;"&gt;&lt;?php echo $row_edit['have_seen']; ?&gt;&lt;/a&gt;</font id=code></pre id=code>

But when I use the 'print' in the PHP code some things doesn't work. I have, e.g., change the " to an '.

The idea is, when the fieldname has a specific value the costumer can change this value by updating the fieldname with a hyperlink to the update.php page. When the costumer has updated the field, (and does not match the specific value) the value of the fieldname must be shown and NOT the hyperlink.

Thanks in advance...

Reply to this topic