cmb Posted April 6, 2012 Share Posted April 6, 2012 how can i put an if statement inside an echo this is what i want to do <?php echo "<li> <a class='thumb' href='../images/Sections/pinkpanthers/" . $year . "/" . $sessions . "/" . $day . "/" . $y . ".jpg' title=''> <img src='../images/Sections/pinkpanthers/" . $year . "/" . $sessions . "/" . $day . "/thumbs/" . $y . ".jpg ' /></a><div class='caption'> <div class='download'><a href='../images/Sections/pinkpanthers/" . $year . "/" . $sessions . "/" . $day . "/big/" . $y . ".jpg ' target='_blank' />Download</a> </div><div class='image-desc'>" . if ($count == 1){echo "<a href='tag.php?tag=$name'" . $name . ">" . $name . "</a>";}if ($count > 1){$z = 0;$w = $count - 1;while ($z <= $w){$p = $multi[$z];echo "<a href='tag.php?tag=$p'" . $p . ">" . $p . "</a>";$z++;}} . "</div></div></li>"; ?> all the code works wright up until i added the if statements in the last little bit Link to comment https://forums.phpfreaks.com/topic/260434-if-inside-an-echo/ Share on other sites More sharing options...
chriscloyd Posted April 6, 2012 Share Posted April 6, 2012 Cant, I think the best way would be to run the statement before the echo and then add the variable. Also if you are using echo ""; you can add a var easy if you do echo "{$varname}"; instead of the ". $var ." Link to comment https://forums.phpfreaks.com/topic/260434-if-inside-an-echo/#findComment-1334872 Share on other sites More sharing options...
cmb Posted April 6, 2012 Author Share Posted April 6, 2012 how would i do this while part <?php $z = 0; $w = $count - 1; while ($z <= $w){ $p = $multi[$z]; $keys = "<a href='tag.php?tag=$p'" . $p . ">" . $p . "</a>"; $z++; } ?> because how i have it now it only shows 1 of the keywords not all of them Link to comment https://forums.phpfreaks.com/topic/260434-if-inside-an-echo/#findComment-1334873 Share on other sites More sharing options...
cmb Posted April 6, 2012 Author Share Posted April 6, 2012 i just broke up the echo so i could write this code here like this <?php while ($y <= $x){ $name = $tags[ $y . '.jpg']; $multi = explode(',',$name); $count = count($multi); echo "<li> <a class='thumb' href='../images/Sections/pinkpanthers/" . $year . "/" . $sessions . "/" . $day . "/" . $y . ".jpg' title=''><img src='../images/Sections/pinkpanthers/" . $year . "/" . $sessions . "/" . $day . "/thumbs/" . $y . ".jpg ' /></a><div class='caption'><div class='download'><a href='../images/Sections/pinkpanthers/" . $year . "/" . $sessions . "/" . $day . "/big/" . $y . ".jpg ' target='_blank' />Download</a></div><div class='image-desc'>"; if ($count == 1){ echo "<a href='tag.php?tag=$name'" . $name . ">" . $name . "</a>"; } if ($count > 1){ $z = 0; $w = $count - 1; while ($z <= $w){ $p = $multi[$z]; echo "<a href='tag.php?tag=$p'" . $p . ">" . $p . "</a> "; $z++; } } echo "</div></div></li>"; $y ++ ; } ?> Link to comment https://forums.phpfreaks.com/topic/260434-if-inside-an-echo/#findComment-1335012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.