spits it out twice!?<

liunx

Guest
Ok... i've got a blog that I made myself on my <!-- w --><a class="postlink" href="http://www.karinne.net">www.karinne.net</a><!-- w --> site. As you can see it's spitting out todays blogs twice!?

Here's my code

<?
// get date groupings
$groupdate = pg_exec("select id, blogwday, blogmonth, blogday, blogyear from blog group by id, blogwday, blogmonth, blogday, blogyear order by id desc limit 5");
$max = pg_numrows($groupdate);
for ($cnt=0; $cnt<$max; $cnt++) {
$row = pg_fetch_array($groupdate, $cnt);
$blogwday = $row['blogwday'];
$blogmonth = $row['blogmonth'];
$blogday = $row['blogday'];
$blogyear = $row['blogyear'];

$blogdate = "» ".$blogwday." - ".$blogmonth." ".$blogday.", ".$blogyear."";?>

<div class="blogdate"><?=$blogdate?></div>

<?
//get the blog(s) that corresponds to the date
$blogs = pg_exec("select * from blog where blogwday='$blogwday' and blogmonth='$blogmonth' and blogday='$blogday' and blogyear='$blogyear' order by blogwday, id desc");
$max2 = pg_numrows($blogs);

for ($cnt2=0; $cnt2<$max2; $cnt2++) {
$row2 = pg_fetch_array($blogs, $cnt2);
$blogid = $row2['id'];

//count the comments associated with this blog
$comments = pg_exec("select count(id) as count from blog_comments where blogid='$blogid'");
$row_comments = pg_fetch_array($comments);
$count = $row_comments['count'];

// a simple replace
$row2['blog'] = preg_replace("/&/", "&", $row2['blog']);
?>
<div class="title"><?=$row2['title']?></div>
<?=$row2['blog']?>
<div class="blogfooter">Posted by <?=$row2['blogger']?> @ <?=$row2['blogtime']?> | Category: <a href=http://www.htmlforums.com/archive/index.php/"/all-by-category.php?cat=<?=$row2['category']?>"><?=$row2['category']?></a> | <a href=http://www.htmlforums.com/archive/index.php/"/with-comments.php?id=<?=$row2['id']?>">Comments (<?=$count?>)</a></div>
<?}
}?>


help?!since you have more than 1 for the same day, i'll say don't group by on id
and should you order by day instead of id?

so
$groupdate = pg_exec("select blogwday, blogmonth, blogday, blogyear from blog group by blogwday, blogmonth, blogday, blogyear order by blogyear desc, blogmonth desc, blogday desc limit 5");

what's blogwday and blogday??
if blogwday is the "word" of the day, you could use
date("l",mktime(0,0,0,blogmonth,blogday,blogyear));
instead of storing in the db...
well you could only use 1 field for the date in format MMDDYYYY and display like you want with date('l - F jS, Y',12182003);Use YYYYMMDD date ordering -- it sorts numerically.yep good one
but have to change my date() call to
date('l - F jS, Y',mktime(0,0,0,substr($date,4,2),substr($date,6,2),substr($date,0,4)));the reason why i have all those in different fields it's cause it was easier for me to count how many by month and to group them. I don't know how to be able to display just certain chunks of the dates when i store it like yyyymmdd or another format!?!i never use PostgreSQL but i bet you could use some substring function...
ex:
select substring(date,1,4) as year from blog group by year

but i didn't test that!

(mysql seem to start at 1 unlike php that start at 0)
 
Back
Top