Jump to content

Trying to Call the last posts to phpbb -- having trouble!!


rich_greeny

Recommended Posts

hi everyone, i'm new here and a bit of a php/mysql noob too. I'm trying to call the last posts from the forum to put on the index of my website, and the only output i've managed  to squeeze out is "Array Array Array Array". Which is a little frustrating!! Heres the code, any ideas?


[code]<?php

$MySQL_hostname = "localhost";
$MySQL_username = "****";
$MySQL_password = "****";
$connection = @mysql_connect($MySQL_hostname,$MySQL_username,$MySQL_password) or die("Couldn't connect");
$db_name = "****";
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database");
$table_name = "phpbbmem_posts";
$result = mysql_query("SELECT * FROM $table_name ORDER BY post_time DESC LIMIT 4");

while ($row = mysql_fetch_array($result)) {

$idTopic = $row["topic_id"];
$idPoster = $row["poster_id"];

$user=mysql_fetch_array(mysql_query("SELECT username FROM phpbbmem_users WHERE user_id='$idPoster'"));
$thread=mysql_fetch_array(mysql_query("SELECT topic_title FROM phpbbmem_topics WHERE topic_id='$idTopic'"));



echo "<tr style=\"width: 40%;\" height=\"0\" border=\"1\" bordercolor=\"black\">$thread</tr>\n";
echo "<tr style=\"width: 20%;\" height=\"0\" border=\"1\" bordercolor=\"black\">$username</tr>\n";

}

mysql_close();

?>[/code]

Thanks in advance.
Link to comment
Share on other sites

its allways better to split up, and not compound your query statements so its easier to read and follow problems, it means more code but its a small price so:-
[code]
$query = "SELECT username FROM phpbbmem_users WHERE user_id='$idPoster'";
$result = mysql_query($query)or die ('Error in query: $query. ' . mysql_error());
$user = mysql_result($result,0); //uses the first one if many are pulled

$query1 = "SELECT topic_title FROM phpbbmem_topics WHERE topic_id='$idTopic'";
$result1 = mysql_query($query1)or die ('Error in query: $query1. ' . mysql_error());
$thread = mysql_result($result1,0); //uses the first one if many are pulled

[/code]

put those in place of your two lines
[code]
$user=mysql_fetch_array(mysql_query("SELECT username FROM phpbbmem_users WHERE user_id='$idPoster'"));
$thread=mysql_fetch_array(mysql_query("SELECT topic_title FROM phpbbmem_topics WHERE topic_id='$idTopic'"));
[/code]
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.