 |
 |
 |
 |
Registered: 01/02/10
Posts: 70
|
|
|
 |
 |
 |
 |
|
 |
 |
 |
 |
#165652 - 10/10/06 02:38 PM
Re: Converting datetime
[Re: Gizmo]
|
member
|
Registered: 09/02/04
Posts: 164
Loc: Leiden, The Netherlands
|
|
Final version:
<?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 02:47 PM)
|
|
Top
|
|
|
|
|
 |
 |
 |
 |
|
|