Page 1 of 1

IF condition

Posted: Tue Jan 06, 2004 2:50 am
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

Posted: Tue Jan 06, 2004 4:17 am
by m3mn0n

Posted: Tue Jan 06, 2004 4:23 am
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 ?>

Posted: Tue Jan 06, 2004 5:31 am
by vinny199
Thank you all!
Works great

Posted: Tue Jan 06, 2004 6:23 am
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 
?>

Posted: Tue Jan 06, 2004 7:17 am
by JAM
or

Code: Select all

echo ($row_rsMP3['price'] == "FREE" ? "<a href='{$row_rsMP3['downloadurl']}'>Download Free Track</a>" : "");

Posted: Tue Jan 06, 2004 9:59 am
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