Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Unhappy if else statement not working?!

    My if else statement at the top of my code does not work?! can someone please help me?!
    it's just writing out the code on the page
    Code:
    echo <<<EOF
      <a title="$HeaderID" id="$HeaderID" name="$HeaderID"></a>
      if ($HeaderDate = date("d")+6) {
      <div class="poo">
      }
      else
      {
      <div class="entry_header">
      }
        <b>Header Name:</b> $HeaderName <a href="edit.php?HeaderID=$HeaderID"><img src="images/picture_edit.png" border="0" /></a> <a href="upload.php?HeaderID=$HeaderID"><img src="images/picture_right.png" border="0" /></a><br />
          <b>Country:</b> <a href="http://www.avert.org/photo_search.php?search_keyword_id=&search_country_id=country-$CountryID&page_type=thumbnails&search=search" target="_blank">$Country</a> <b>Keywords:</b> 
    EOF;
    //loop through Keywords 
          $i = 0;
    while ($row1 = mysql_fetch_array($result2))
    {
        if ($i++ > 0)
        {
            echo ', ';
        }
       $Keyword = $row1['keyword'];
    	  $KeywordID = $row1['keyword_id'];
           echo '<a href="http://www.avert.org/photo_search.php?search_keyword_id='.$KeywordID.'&search_country_id=&page_type=thumbnails&search=search" target="_blank" >'.$Keyword.'</a>';
    	   echo ' <a href="editkeywords.php?HeaderID='.$HeaderID.'">[Edit]</a>';
    }

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I don't think it's possible to execute php code inside heredoc except for variables or calling of class's member function. You may need to end your heredoc before if statement and then start again.
    (If the string is not so big, then a double quote would be easy)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    ok i changed it, now i get:
    Parse error: syntax error, unexpected T_SL in /Users/avertstaff/Sites/johns/headers/display.php on line 146


    line146:
    Code:
    echo <<<EOF
    Code:
     echo "<a title=".$HeaderID." id=".$HeaderID." name=".$HeaderID."></a>";
      if ($HeaderDate = date("d")+6) {
    echo "<div class=\"poo\">";
      }
      else
      {
    echo "<div class=\"entry_header\">";
      }
    echo <<<EOF 
    <b>Header Name:</b> $HeaderName <a href="edit.php?HeaderID=$HeaderID"><img src="images/picture_edit.png" border="0" /></a> <a href="upload.php?HeaderID=$HeaderID"><img src="images/picture_right.png" border="0" /></a><br />
          <b>Country:</b> <a href="http://www.avert.org/photo_search.php?search_keyword_id=&search_country_id=country-$CountryID&page_type=thumbnails&search=search" target="_blank">$Country</a> <b>Keywords:</b> 
    EOF;
    //loop through Keywords 
          $i = 0;
    while ($row1 = mysql_fetch_array($result2))
    {
        if ($i++ > 0)
        {
            echo ', ';
        }
       $Keyword = $row1['keyword'];
    	  $KeywordID = $row1['keyword_id'];
           echo '<a href="http://www.avert.org/photo_search.php?search_keyword_id='.$KeywordID.'&search_country_id=&page_type=thumbnails&search=search" target="_blank" >'.$Keyword.'</a>';
    	   echo ' <a href="editkeywords.php?HeaderID='.$HeaderID.'">[Edit]</a>';
    }

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Well, I think it;s due to a blank space after echo <<<EOF . Press 'End' key and then use 'backspace' to remove it.
    Quote Originally Posted by http://in2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
    heredoc syntax: <<<. After this operator, an identifier is provided, then a newline.
    BTW, I think there are some errors in
    if ($HeaderDate = date("d")+6)
    Last edited by abduraooft; 07-17-2008 at 11:25 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Don't see anything wrong there, apart from here

    if ($HeaderDate = date("d")+6) {

    Should be

    if ($HeaderDate == date("d")+6) {

  • #6
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    it works now but it doesn't change the class like i want it to do, i want it o do somthing like:
    from the most recent header added, 6 days within that
    so like:

    $HeaderDate = 11th July

    6 days left = 12th
    5 days left = 13th
    4 days left = 14th
    3 days left = 15th
    2 days left = (Today) 16th July
    1 day left = 17th

    18th July = you must now change your header!

    and then when I add a new header:

    6 days left = 19th July
    and so on!

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by jarv
    it works now
    what was the issue? Post your current code.
    date("d")+6
    $HeaderDate = 11th July
    How $HeaderDate get a value like 11th July
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    $HeaderDate = 11th July and each week for 10 weeks or so before then!
    I want to show messages for the latest date added and each day for 6 days after!


  •  

    Posting Permissions

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