I’m building a blog. This is the code to display the entries. I only need the variables to display if they exist. Not all bog posts have an image, video, ect.
[php]<?php
$blogpost = “”;
$sql = mysql_query(“SELECT * FROM Entries ORDER BY date_added DESC”);
$EntriesCount = mysql_num_rows($sql);
if ($EntriesCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row[“id”];
$title = $row[“title”];
$entry = $row[“entry”];
$video = $row[“video”];
$entry2 = $row[“entry2”];
$link = $row[“link”];
$date_added = strftime("%A %B %e, %G %l:%M%p %Z", strtotime($row[“date_added”]));
$blogpost .= ’
<p id="entry">' . $entry . '</p>
' . $video . '
<br />
<br />
<img src="uploads/' . $id . '.jpg" alt="' . $title . '" id="postimage" />
<p id="entry2">' . $entry2 . '</p>
<a href="' . $link . '" target="_blank">' . $link . '</a>
<br />
<div id="date"><a href="entry.php?id=' . $id . '">Read More</a> | ' . $date_added . '</div>
</div>';
}
}
else {
$blogpost = “No blog posts to display.”;
}
mysql_close();
?>[/php]