Site Links
Home
Features
Documentation
Pricing & Order
Members Area
Support Options
UBBDev.com
UBBWiki.com
Who's Online
6 registered (Ruben, SD, nims2, Dunny, GregK, SteveS), 22 Guests and 14 Spiders online.
Key: Admin, Global Mod, Mod
Featured Member
mig
mig
Registered: 07/22/05
Posts: 39
Top Posters (30 Days)
Ruben 65
SD 57
Gizmo 53
gliderdad 32
Iann128 22
Dunny 21
Steve C 20
driv 18
dbremer 16
Stan 15
Latest Photos
Testing
Basildon Train Station
Basildon Town Centre looking from the rounderbout
Basildon Town Square
Gizzo Marx
Page 1 of 2 1 2 >
Topic Options
#165530 - 10/10/06 12:18 AM Converting datetime
Yomar Offline
member
Registered: 09/02/04
Posts: 164
Loc: Leiden, The Netherlands
With my very limited PHP programming skills (don't laugh!) I have somehow managed to pull data from the forum database and make my own custom islands showing full postings:

http://www.fabulaemarrii.com/guildnews2.php

...using this code:

PHP:

<?php
  // Open and select database
  $link = mysql_connect('topsecretserver','topsecretdatabasename','topsecretpassword');
  if (!$link)
    {
    die('Cannot connect to server: '.mysql_error());
    }

  $db = mysql_select_db('topsecretdatabase',$link);
  if (!$db)
    {
     die('Cannot select database: '. mysql_error());
    }

  // Find out post id's
      $query = "SELECT * FROM ubbt_TOPICS where FORUM_ID=18 ORDER BY POST_ID DESC";
      $result = mysql_query($query);
      if (!$result)
        {
        die('Cannot read from database: '.mysql_error());
        }
      $num_results = mysql_num_rows($result);
      echo '<i>Found '.$num_results.' results. </i>';

  echo '</tr><tr bgcolor="#555555"><td>';

  // Build table

      for ($i=0; $i <$num_results; $i++)
        {
        $rowid = mysql_fetch_array($result);
        $postid=$rowid['POST_ID'];

        $queryposting = "SELECT * FROM ubbt_POSTS where POST_ID=".$postid."";
        $resultposting = mysql_query($queryposting);
        if (!$result)
          {
          die('Cannot read from database: '.mysql_error());
          }
        $rowposting = mysql_fetch_array($resultposting);
        $subject=$rowposting['POST_SUBJECT'];
        $time=$rowposting['POST_POSTED_TIME'];
        $body=$rowposting['POST_BODY'];
        $userid=$rowposting['USER_ID'];

        if ($userid=='211')
          {
          $username="Catkin";
          }
        elseif ($userid=='2')
          {
          $username="Yomarbalthasar";
          }
        else
          {
          $username="We have no idea, really";
          }

      echo '<b><font color="white">'.$time.': '.$subject.'</b></font><br>';
      echo '</td></tr><tr bgcolor="#CCCCCC"><td>'.$body.'<br><i>Posted by '.$username.'</i>';
      echo '</td></tr><tr bgcolor="#555555"><td>';
      }
?>



So far so good. Now the last thing I need to do to get this working is convert the time of the posting. I can pull it from the database, but I get some illegible number. How do I convert this number to a more legible format, preferably YYYYMMDD HHMM (24-hour format)?

There's probably one command for this, but to find out what works, I need to know in what format this data is stored in the first place.


Edited by Yomar (10/10/06 03:32 AM)
Top
Express Hosting
Express Hosting "We are the official hosting company of UBB.threads. Ask us about our free migration services to migrate your UBB.threads installation."
#165547 - 10/10/06 03:51 AM Re: Converting datetime [Re: Yomar]
Gizmo Offline

Registered: 06/05/06
Posts: 14904
Loc: Portland, OR; USA
The date in the database is stored as a Unix Epoch, you can manipulate date() to convert from unix epoch as: date("format", $time);
_________________________
Forums: UGN Security & VNC Web Design & Development
UBB.Threads: UBB.Wiki, My UBBSkins, UBB.Sitemaps
Longtime UBB Supporter, UBB Beta Tester & Resident Post-A-Holic.
UBB Modifications, Styling, Coding Services, Disaster Recovery, and more!
Top
#165552 - 10/10/06 04:35 AM Re: Converting datetime [Re: Gizmo]
Yomar Offline
member
Registered: 09/02/04
Posts: 164
Loc: Leiden, The Netherlands
Fantastic Gizmo! It's finally working!

Thank you very much.
Top
#165555 - 10/10/06 04:48 AM Re: Converting datetime [Re: Yomar]
Gizmo Offline

Registered: 06/05/06
Posts: 14904
Loc: Portland, OR; USA
Not a problem... The sad thing is that I know all of this odd stuff offhand lol... I had to make a date converter when recoding things for one of my RPG help sites, the old system stored stuff as physical dates vs Unix Epoch and i wanted to change the format and figured the best way would be to store as unix epoch and change it on the fly...

Let me know how your modding goes :).
_________________________
Forums: UGN Security & VNC Web Design & Development
UBB.Threads: UBB.Wiki, My UBBSkins, UBB.Sitemaps
Longtime UBB Supporter, UBB Beta Tester & Resident Post-A-Holic.
UBB Modifications, Styling, Coding Services, Disaster Recovery, and more!
Top
#165652 - 10/10/06 03:38 PM Re: Converting datetime [Re: Gizmo]
Yomar Offline
member
Registered: 09/02/04
Posts: 164
Loc: Leiden, The Netherlands
Final version:

PHP:

<?php
  // Open and select database
  $link = mysql_connect('server','username','password');
  if (!$link)
    {
    die('Cannot connect to server: '.mysql_error());
    }

  $db = mysql_select_db('database',$link);
  if (!$db)
    {
     die('Cannot select database: '. mysql_error());
    }

  // Find out post id's
      $query = "SELECT * FROM ubbt_TOPICS where FORUM_ID=18 ORDER BY POST_ID DESC";
      $result = mysql_query($query);
      if (!$result)
        {
        die('Cannot read from database: '.mysql_error());
        }
      $num_results = mysql_num_rows($result);
      echo '<i>Found '.$num_results.' results. </i>';

  echo '</tr><tr bgcolor="#555555"><td>';

  // Build table

      for ($i=0; $i <$num_results; $i++)
        {
        $rowid = mysql_fetch_array($result);
        $postid=$rowid['POST_ID'];

        $queryposting = "SELECT * FROM ubbt_POSTS where POST_ID=".$postid."";
        $resultposting = mysql_query($queryposting);
        if (!$result)
          {
          die('Cannot read from database: '.mysql_error());
          }
        $rowposting = mysql_fetch_array($resultposting);
        $subject=$rowposting['POST_SUBJECT'];
        $time=$rowposting['POST_POSTED_TIME'];
        $timeconvert=date("d-m-Y, H:i", $time);
        $body=$rowposting['POST_BODY'];
        $userid=$rowposting['USER_ID'];

        if ($userid=='211')
          {
          $username="Catkin";
          }
        elseif ($userid=='2')
          {
          $username="Yomarbalthasar";
          }
        else
          {
          $username="We have no idea, really";
          }

      echo '<b><font color="white">'.$timeconvert.': '.$subject.'</b></font><br>';
      echo '</td></tr><tr bgcolor="#CCCCCC"><td>'.$body.'</td></tr>';
      echo '<tr bgcolor="#CCCCCC"><td align="right"><i>Posted by '.$username.'</i>
<a href="http://www.fabulaemarrii.com/ubbthreads7/ubbthreads.php?ubb=showflat&Number='
.$postid.'">Respond!</a>';
      echo '</td></tr><tr bgcolor="#555555"><td>';
      }
?>



I'm definitely not a professional PHP programmer, but at least it works. Feel free to adapt the script and use it for your own purposes. The words server, username, password and database must of course be replaced with your own data.

Basically this script pulls all postings from forum number 18, then reverses the order of those postings (newest postings on top), links the ID's of those postings with the actual bodies of the postings, and then wraps the result in a nice table. It also pulls/converts the timestamp of the posting and links the user ID of the poster to the actual user name (in our case only 3 users have the right to post on said forum, so chances are you need to change this into something more dynamic and sophisticated). Last but not least a link to said posting is added, so that people can post straight from the content island.

Note that this wrap only works in a specific context, as the beginning of the table is not defined. So you will also need to tweak the <td>, <tr> and <table> tags a bit.


Edited by Yomar (10/10/06 03:47 PM)
Top
#165679 - 10/10/06 06:15 PM Re: Converting datetime [Re: Yomar]
Gizmo Offline

Registered: 06/05/06
Posts: 14904
Loc: Portland, OR; USA
Not too shabby, I'm sure I'll adapt the world out of it ;)...
_________________________
Forums: UGN Security & VNC Web Design & Development
UBB.Threads: UBB.Wiki, My UBBSkins, UBB.Sitemaps
Longtime UBB Supporter, UBB Beta Tester & Resident Post-A-Holic.
UBB Modifications, Styling, Coding Services, Disaster Recovery, and more!
Top
#165701 - 10/10/06 07:51 PM Re: Converting datetime [Re: Gizmo]
David Dreezer Offline

Pooh-Bah
Registered: 07/21/06
Posts: 2199
I think i'd use a LIMIT on the select for topics.


Now expand on this to make it server friendly. Write the results to a file. Check the timestamp of the file. If it's younger than 5 minutes old server the content right off the file instead of doing the database hit. If the file is older than 5 minutes unlink it, do the database work, write the file, then server it.
_________________________
This thread for sale. Click here!
Top
#165720 - 10/11/06 12:40 AM Re: Converting datetime [Re: David Dreezer]
Yomar Offline
member
Registered: 09/02/04
Posts: 164
Loc: Leiden, The Netherlands
Aye, I will definitely implement a LIMIT function - when the time is there, as it will take a year or so before that actually becomes a problem

The same for the server-friendliness. We're not that high-profile (maybe like 50 visitors a day), so we can handle this. But I totally agree you need to work with files and timestamps if you have a site with many visitors.
Top
#165725 - 10/11/06 02:09 AM Re: Converting datetime [Re: Yomar]
Gizmo Offline

Registered: 06/05/06
Posts: 14904
Loc: Portland, OR; USA
'eh I'm not good with caching myself or i'd help lol... Though I may get super bored, so who knows...
_________________________
Forums: UGN Security & VNC Web Design & Development
UBB.Threads: UBB.Wiki, My UBBSkins, UBB.Sitemaps
Longtime UBB Supporter, UBB Beta Tester & Resident Post-A-Holic.
UBB Modifications, Styling, Coding Services, Disaster Recovery, and more!
Top
#165800 - 10/11/06 05:36 PM Re: Converting datetime [Re: Gizmo]
Gizmo Offline

Registered: 06/05/06
Posts: 14904
Loc: Portland, OR; USA
Ok, so I got bored and made my own rendition of UBBNews for 7.0 (albeit sloppy, but hey it works, although no caching just like yours)...

UBBDev: UBB.News 7.0
_________________________
Forums: UGN Security & VNC Web Design & Development
UBB.Threads: UBB.Wiki, My UBBSkins, UBB.Sitemaps
Longtime UBB Supporter, UBB Beta Tester & Resident Post-A-Holic.
UBB Modifications, Styling, Coding Services, Disaster Recovery, and more!
Top
Page 1 of 2 1 2 >



Moderator:  AllenAyres, Harold, Ian, Ron M 
Shout Box

Today's Birthdays
No Birthdays
Recent Topics
A positive note
by SteveS
Yesterday at 09:36 PM
How to locate links to particular site if they are only used in images?
by Conrad
02/10/12 09:41 PM
Pictures not displaying
by Marker23
02/09/12 10:04 PM
Issue with logging out constantly
by Flanuva
02/09/12 07:05 PM
Long thread, UBB code not parsing
by Bad Frog
02/09/12 07:47 AM
Forum Stats
10213 Members
36 Forums
33666 Topics
180902 Posts

Max Online: 978 @ 06/24/07 11:19 PM
Random Image