Forewarning: I am bad at CSS.
Hello,
I am working on a little message board which displays the 3 most recent posts.
I would also like the user to choose how many posts are displayed on one screen,
say 5 or 10 posts.
Currently I have it so that all posts are printed out in this manner:
while ($i < $d){
// $d is entered by the user to determine how many posts are to be displayed.
if ($i == $id_Max){
echo "Reached last known post.";
break;
}
$query2 = $con->prepare(
"SELECT postName, postPath FROM " . $table .
" WHERE id=(SELECT MAX(id-".$i.") FROM " . $table . ")"
);
$query2->execute();
$result2 = $query2->fetch();
$path = $result2["postPath"];
$file = file_get_contents($path);
echo "<article class = 'entry'>";
echo "<section id = 'entryTitle'>";
echo $result2["postName"] . "<br />";
echo "</section>";
echo $file;
echo "<br />";
echo "</article>";
$i++;
}
So, each post that is printed has the class of entry. With this I gave each post a border, but I want to make it so that there is a space of about 5px between them.
I set their position: relative and top: 5px but it only takes effect on the top most entry and moves them all down by 5px from the very top of the page.
Essentially, I want to have something work globally with out having to write out something for each possible post. #entry1, #entry2…
I am look not really for how to do this specific thing, but more of something that I can learn from to apply in future things.
Thanks,
– Michael Mitchell
(If I was not clear, please tell me and I will attempt to explain better.)
There’s a few things I see going on wrong here.
First of all, spacing between elements is typically handled with margins:
Second, it looks like you are making multiple requests to the database when you don’t really need to. The query you want looks like this:
This will give you a list of the top entries that you can iterate through and is much faster than making multiple requests. If you want the number of entries return to be configurable, make absolutely sure you are sanitizing/escaping the value.