vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Categorizing posts by date (https://vborg.vbsupport.ru/showthread.php?t=58768)

Alex Taylor 11-23-2003 05:51 AM

Categorizing posts by date
 
I'm trying to write a journal-type script.. The main page displays all the journal entries, organized by descending date. I want to make it so that if a user has, say, 3 posts on the same date, it will automatically organize all the posts from that day under one header. Example:

Post 1 - Jan 1st
Post 2 - Jan 1st
Post 3 - Jan 1st
Post 4 - Jan 4th

Instead of looking like that, I want it to look like this:

Jan 1st
-Post 1
-Post 2
-Post 3

Jan 4th
-Post 4

Any ideas on how I would accomplish this? Any tips are appreciated! I've played around a tiny bit with the GROUP BY control when I'm pulling data out of the dB but I can only seem to get it to display the first rows with each different date.

assassingod 11-23-2003 08:08 AM

I've had a quick try (and seeing as i'm not sure how your table is setup) and i've got a little way but sadly it's not the most efficient way - but i hope you can work around it (or someone posts an easier way to do it)

PHP Code:

<?php
 
//connect to the DB
 
$conn mysql_connect("localhost","root","")
  or die(
"Couldnt connect"); //failed?
 
$rs mysql_select_db("postdate"$conn)
  or die(
"Couldnt select DB!"); // failed?
 
     //run query
     
$querytime mysql_query("SELECT * FROM post WHERE postdate = '1st Jan'");
 
     
// loop results
     
while($posted mysql_fetch_array($querytime))
     {
          
$poststuff .= "-$posted[post]<br />";
     }
 
     
//run query again
     
$querytime1 mysql_query("SELECT * FROM post WHERE postdate = '4th Jan'");
 
     
// loop results again
     
while($posted1 mysql_fetch_array($querytime1))
     {
          
$poststuff2 .= "-$posted1[post]<br />";
     }
 
//echo crappy results, i had to hardcode in the dates sadly
echo("1st Jan <br />$poststuff<br />4th Jan<br /> $poststuff2 ");
?>


Alex Taylor 11-23-2003 03:03 PM

Thanks, but unfortunately I can't hardcode the dates. The GROUP BY function works in that it takes each different date and displays the first row of each, but it just doesn't continue and display all the other similar dates under one another.

Alex Taylor 11-25-2003 12:54 AM

Anybody? Beuler?

Issvar 11-25-2003 09:55 AM

Use a query like "SELECT post,date FROM posts ORDER BY date", and loop through it, like
Code:

$curdate=""
while ($data = mysql_fetch_object($queryresults)) {
  if ($data->date != $curdate) {
    echo '<br>'.$data->date.'<br>';
    $curdate = $data->date;
  }
  echo $data->post.'<br>';
}



All times are GMT. The time now is 07:33 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01032 seconds
  • Memory Usage 1,725KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete