SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Oct 2002
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Code Inside PHP, " or '???

    Hey,

    Ok, I want to output something depending on if it exists or not. The variable $flyer is in a database field.

    Now the problem appears to be inserting php code inside the other php code.

    I'm not sure whether to use ", ' or what...everything I do doesn't work. The code is below.

    PHP Code:
    <?php
     
    #Check if a flyer is availble for meeting
     
    if ($flyer=="")
     
    {
     
    echo 
    "A flyer is not available for this meeting";
     
    }
     
    else
     
    {
     
    echo 
    "<a href="<?php echo "$flyer;' ?>'>Click Here To Download Flyer</a>";
     
    }
     
    ?>
    Any ideas?

  2. #2
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    echo "<a href=\"".$flyer."\">Click Here To Download Flyer</a>";

    Hope this helps.

  3. #3
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DarkAngelBGE
    echo "<a href=\"".$flyer."\">Click Here To Download Flyer</a>";

    Hope this helps.
    This is in no way meant to be nitpicky...

    But if you're going to go to all the hassle of separating the variable from the string, so as to reduce parsing time, at least use single quotes, so the PHP parser won't even have to look:

    (Example A):
    PHP Code:
    echo "<a href=\"$flyer\">Click Here To Download Flyer</a>"
    Or, much better:
    (Example B):
    PHP Code:
    echo '<a href="'$flyer'">Click Here To Download Flyer</a>'
    My name is Steve, and I'm a super-villian.

  4. #4
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lieut_data
    This is in no way meant to be nitpicky...

  5. #5
    SitePoint Addict
    Join Date
    Oct 2002
    Posts
    311
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked a treat, thanx very much =)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •