Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-23-2003, 05:51 AM
Alex Taylor Alex Taylor is offline
 
Join Date: Nov 2003
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 11-23-2003, 08:08 AM
assassingod's Avatar
assassingod assassingod is offline
 
Join Date: Jul 2002
Posts: 3,337
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 ");
?>
Reply With Quote
  #3  
Old 11-23-2003, 03:03 PM
Alex Taylor Alex Taylor is offline
 
Join Date: Nov 2003
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 11-25-2003, 12:54 AM
Alex Taylor Alex Taylor is offline
 
Join Date: Nov 2003
Posts: 8
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anybody? Beuler?
Reply With Quote
  #5  
Old 11-25-2003, 09:55 AM
Issvar Issvar is offline
 
Join Date: Mar 2002
Posts: 68
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>';
}
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:25 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04248 seconds
  • Memory Usage 2,206KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete