Jump to content

Adding Username and Date?


Stargate05

Recommended Posts

Hey guys,

 

Using this code, does anyone see how I could add the user name of the person who made the post and the time and date it was posted at? This code already shows the title of the topic and gives a link to the topic in the forum.

 

 

<?php

$connection = mysql_connect("localhost", "imissth1_phpb4", "[1E199M[1y8W") or die("Service Temporarily Unavailable");

$db = mysql_select_db("imissth1_phpb4",$connection) or die("Service temporairly unavailable");

$sql = "select * from phpbb_topics order by topic_last_post_time desc limit 0,10";

$result = mysql_query($sql) or die("Service temporairly unavailable");

for($x=1;$x<=10;$x++){

$row = mysql_fetch_array($result);

echo "<a href = \"http://www.codenamekingdom.com/forum/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]\" target = \"_blank\">$row[topic_title]</a><br><br>";

}

?>

 

Don't know how many of you use MySql but thanks in advance guys!

Link to comment
Share on other sites

There's only one echo() in the code above:

 

echo "<a href = \"http://www.codenamekingdom.com/forum/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]\" target = \"_blank\">$row[topic_title]</a><br><br>";

 

If the syntax in that line doesn't make sense to you, just post the field names, and I'm sure someone (if not me) will be by shortly to help.

Link to comment
Share on other sites

use this code to echo it

 

<?php
$connection = mysql_connect("localhost", "imissth1_phpb4", "[1E199M[1y8W") or die("Service Temporarily Unavailable");
$db = mysql_select_db("imissth1_phpb4",$connection) or die("Service temporairly unavailable");
$sql = "select * from phpbb_topics order by topic_last_post_time desc limit 0,10";
$result = mysql_query($sql) or die("Service temporairly unavailable");
for($x=1;$x<=10;$x++){
   $row = mysql_fetch_array($result);
   print_r($row);// this will print everything in the array including the array name
   echo "<a href = \"http://www.codenamekingdom.com/forum/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]\" target = \"_blank\">$row[topic_title]</a><br><br>";
}
?>

Link to comment
Share on other sites

Thanks BillyBoB but all I got was a huge amount of seemingly random data ;P

 

Pikachu, I would really appreciate it if you could, here are the field names for the username and time posted: topic_last_poster_name (username to last post in topic) and topic_last_post_time (last time topic was posted in)

 

I was hoping to see something like this:

 

TOPIC TITLE

Last Posted in by: topic_last_poster_name

On: topic_last_post_time

 

Only thing is I dont understand the time... in the database for example, its just a random number... ie. 1278533748

How would you turn that into an actual date?

 

Thanks a lot for all the help!

Link to comment
Share on other sites

when you look into the database can you find the column topic_last_post_time and see what type it is.

 

if the date is stored with php timestamp values then its type would be string...

 

your end code would look like

<?php
$connection = mysql_connect("localhost", "imissth1_phpb4", "[1E199M[1y8W") or die("Service Temporarily Unavailable");
$db = mysql_select_db("imissth1_phpb4",$connection) or die("Service temporairly unavailable");
$sql = "select * from phpbb_topics order by topic_last_post_time desc limit 0,10";
$result = mysql_query($sql) or die("Service temporairly unavailable");
for($x=1;$x<=10;$x++){
   $row = mysql_fetch_array($result);
   
   echo "<a href = \"http://www.codenamekingdom.com/forum/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]\" target = \"_blank\">$row[topic_title]</a><br>Last Posted in by: $row[topic_last_poster_name]<br>On: $row[topic_last_post_time]<br><br>";//you may need to convert the time into a workable string...
}
?>

Link to comment
Share on other sites

Thanks for the code BillyBob! Works great except you were right the time is still messed up. Not quite sure what you mean by the "type" though... if you want an example of the value under the topic_last_post_time it would be something like: 1278533748

 

The only other info on that category I can find is:

 

Showing rows 0 - 2 (3 total, Query took 0.0004 sec) [topic_time: 1278533748 - 1278536261]

 

SELECT *

FROM  `phpbb_topics`

ORDER BY  `phpbb_topics`.`topic_time` ASC

LIMIT 0 , 30

 

Does that help or should I be looking for something else?

Link to comment
Share on other sites

i would say that it is a php timestamp.

 

the solution to that would be

<?php
$connection = mysql_connect("localhost", "imissth1_phpb4", "[1E199M[1y8W") or die("Service Temporarily Unavailable");
$db = mysql_select_db("imissth1_phpb4",$connection) or die("Service temporairly unavailable");
$sql = "select * from phpbb_topics order by topic_last_post_time desc limit 0,10";
$result = mysql_query($sql) or die("Service temporairly unavailable");
for($x=1;$x<=10;$x++){
   $row = mysql_fetch_array($result);
   echo "<a href = \"http://www.codenamekingdom.com/forum/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]\" target = \"_blank\">$row[topic_title]</a><br>Last Posted in by: $row[topic_last_poster_name]<br>On: ".date("d-m-y h:i:s", $row['topic_last_post_time'])."<br><br>";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.