I have a php script which I'm using on my newest website, and while I've never had a problem with using this same type of coding before, I'm now getting a lot of errors. Here's the code that I'm using:
$articles_sql = "SELECT * FROM articles ORDER BY added DESC LIMIT 20";
$articles_res = mysqli_query($con, $articles_sql);
while($articles = mysqli_fetch_assoc($articles_res)){
$articles_id = $articles["id"];
$articles_title = $articles["title"];
$articles_text = $articles["text"];
$articles_text = strip_tags($articles_text);
$articles_text = substr($articles_text,0,140);
$articles_added = $articles["added"];
$articles_year = date("Y", strtotime($articles_added));
$articles_date = date("jS F Y, g:ia", strtotime($articles_added));
$display_random_articles .= " // ERROR FOR THIS LINE
<div class=\"block\">
<div class=\"blockAvatar\">
<img class=\"blockAvatarImg\" src=\"images/articles/$articles_year/$articles_id.jpg\" />
<div class=\"blockAvatarCover\"></div>
</div>
<div class=\"blockIcons blockIconPaper\"></div>
<div class=\"blockContent blockContentNarrow\">
<li class=\"blockDate\">$articles_date</li>
<li><strong><a href=\"article.php?id=$articles_id\">$articles_title</a></strong></li>
<li class=\"blockText\">$articles_text...</li>
<li class=\"blockDate\">... <a href=\"article.php?id=$articles_id\">Read On</a> »»</li>
</div>
<div class=\"clearLeft\"></div>
</div>
";
}
Now everything appears to be fine visually but I've just looked at the Error_Log and it's full of the same little errors warning of undefined variables
:
PHP Notice: Undefined variable: display_random_articles in ...
On the line that I outlined above. Does anyone know why I'm getting this error and more importantly, is there any way of getting rid of it?