IF condition

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vinny199
Forum Newbie
Posts: 8
Joined: Sun Nov 16, 2003 12:58 pm
Location: London

IF condition

Post by vinny199 »

Hi,

I have a simple request I think.
I know how to formulate it in asp, but need help in php.

I need to have an example of code for the following:

(I write it as I mean it)

IF {rsMP3.Price}="FREE" THEN SHOW <a href="<?php echo $row_rsMP3['downloadurl']; ?>">Download free track</a>

Basically, if my recordet value for the field MP3.Price is the word FREE then a download link should show as shown above.

could you help me with that?

Thanks,

Vinny
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

hmmm...

Code: Select all

<?php // IF condition starts
if ($row_rsMP3['price']=="FREE") { // Checks for the Free value of the Price field 
?>

<a href="<?php echo $row_rsMP3['downloadurl']; ?>"> Download Free Track</a>

<?php } // IF condition Ends ?>
vinny199
Forum Newbie
Posts: 8
Joined: Sun Nov 16, 2003 12:58 pm
Location: London

Post by vinny199 »

Thank you all!
Works great
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

You could also do this for the same result:

Code: Select all

<?php
if ($row_rsMP3['price'] == "FREE") {
echo "<a href='{$row_rsMP3['downloadurl']}'> Download Free Track</a>";
} // IF condition Ends 
?>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

or

Code: Select all

echo ($row_rsMP3['price'] == "FREE" ? "<a href='{$row_rsMP3['downloadurl']}'>Download Free Track</a>" : "");
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

PHP is lovely isn't it? You can also do:

Code: Select all

<?php

if ($row_rsMP3['price'] == "FREE") {

   echo <<< LINK

<a href="{$row_rsMP3['downloadurl']}">Download Free Track</a>

LINK;

}

?>
-Nay
Post Reply