The following code displays the news article date, title/header, and article.
<h2><?php echo(LATEST_NEWS_ARTICLE_DATE_10);?>
<?php echo(LATEST_NEWS_ARTICLE_HEADER_10);?></h2>
<p><?php echo(LATEST_NEWS_ARTICLE_10);?>
....articles 9 through to 2.....
<h2><?php echo(LATEST_NEWS_ARTICLE_DATE_1);?>
<?php echo(LATEST_NEWS_ARTICLE_HEADER_1);?></h2>
<p><?php echo(LATEST_NEWS_ARTICLE_1);?>
displays:-
article 10:-
31st March 2021 PHP Loop still issues
Whats going on with this loop still
....articles 9 to 2....
article 1:- 31st March 2020 PHP Loop
Whats going on with this loop
but rather than type the code out for each article (eventually 20 articles per page, multi pages), thought I would use a loop.
<?php
for ($x = 10; $x > 0; $x--) {
echo (LATEST_NEWS_ARTICLE_DATE_.$x)." ";
echo (LATEST_NEWS_ARTICLE_HEADER_.$x)."<br>";
echo (LATEST_NEWS_ARTICLE_.$x)."<br><br>";
}
?>
This should display the latest article 10, to the oldest article 1, but instead it displays
LATEST_NEWS_ARTICLE_DATE_10 LATEST_NEWS_ARTICLE_HEADER_10 LATEST_NEWS_ARTICLE_10
.....articles 9 through to 2.....
LATEST_NEWS_ARTICLE_DATE_1 LATEST_NEWS_ARTICLE_HEADER_1 LATEST_NEWS_ARTICLE_1
I must be missing something as its so close. Any help including tutorials to try would be appreciated, I haven't been able to find something yet.
LATEST_NEWS_ARTICLE_DATE_come from? Are you implementing new code for every new post???LATEST_NEWS_ARTICLE_DATE_.$x- That will try and concatenate the value of the constantLATEST_NEWS_ARTICLE_DATE_and the value of the variable$x. Constants are not the correct tool for what you're trying to do. Define a multidimensional array with all the news and iterate through that instead.