I have put a div around the PHP below called box1. What I am trying to do is have a different colored box around every different blog entry. Right now all my entries appear in the same colored box which I dont want. I have tried closing the div after <hr class="hr3" /> because after that a new blog entry begins. When I close the div after h3 the first entry is in the colored box but the other entries are out of place. I have no idea how to do this. Please can someone help!?
The code below is what I currently have on my index page to display my blog entries.
Code:#box1 { width:570px; background-color:#aaa; }How can I seperate blog entries with different colored css boxes?PHP Code:<div id="box1">
<?php
function showinweb($val) {
$val = nl2br($val);
//return returns the value and ends execution of function, so any line below it is ignored
return($val);
}
$page = (!isset($_GET['page'])) ? 1: $_GET['page'];
// Define the number of results per page
$max_results = 3;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = "SELECT id,
DATE_FORMAT(timestamp, '%a.%b.%y') as dateAdded,
title,
entry,
password,
image
FROM php_blog ORDER BY timestamp DESC LIMIT $from, $max_results";
$result = mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" . $sql . "<br />" . mysql_error());
$i =1;
while($row = mysql_fetch_assoc($result)) {
echo "<p class='blogtitle'> <span class='blogtit'>".showinweb($row['title'])."</span></p><br />";
echo "<br /><br />".smiley(showinweb($row['entry']));
echo "<img id='thisimage$i' onmouseover='showdiv(this.id);' onmouseout ='hidediv();' src='entry/blog_images/".showinweb($row['image'])."' alt='' /> ";
echo "<br />".showinweb($row['dateAdded']);
//count number of comments for this post
$result2 = mysql_query ("SELECT id FROM php_blog_comments WHERE entry='".$row['id']."'");
$num_rows = mysql_num_rows($result2);
if ($num_rows > 0) {
//if there's only 1 comment, use singular comment (comment)
if($num_rows == 1){
$word_comment = " comment";
}else{
//use pluralize comment (comments)
$word_comment = " comments";
}
echo " <a href=\"entry/journal.php?id=".$row['id']."\">".$num_rows.$word_comment."</a><br />";
}
else {
echo "<a href=\"entry/journal.php?id=" . showinweb($row['id']) . "\"> Leave a comment</a>"; }
echo '<br /><hr class="hr3" /><br />';
$i++;
}
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM php_blog"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
// echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
// echo "</center>";
?></div>





Bookmarks