...

View Full Version : if else statement not working?!



jarv
07-17-2008, 09:46 AM
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


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>';
}

abduraooft
07-17-2008, 09:54 AM
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)

jarv
07-17-2008, 10:41 AM
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:

echo <<<EOF



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>';
}

abduraooft
07-17-2008, 11:19 AM
Well, I think it;s due to a blank space after echo <<<EOF . Press 'End' key and then use 'backspace' to remove it.

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)

Nightfire
07-17-2008, 11:23 AM
Don't see anything wrong there, apart from here

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

Should be

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

jarv
07-17-2008, 12:20 PM
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!

abduraooft
07-17-2008, 12:27 PM
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

jarv
07-17-2008, 12:50 PM
$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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum