Jump to content

Archived

This topic is now archived and is closed to further replies.

rich_greeny

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

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.

Share this post


Link to post
Share on other sites
Well, you're using mysql_fetch_array(), so you get back an array... I guess you'd probably want to use mysql_result() instead.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
thanks for those replies. I tried the first suggestion, and now i return single results, but in error form, stating "Wrong parameter count for mysql_result() ".

Any ideas on this one?

Share this post


Link to post
Share on other sites
Check the refman... must be parameter order, or something similar.

Share this post


Link to post
Share on other sites
sorry to be annoying, but can you expand on that? I'm not the most proficient mysql/php user, but we've all got to start somewhere!

Share this post


Link to post
Share on other sites
The posted example should work just fine... all you need to specify is a valid resource and a row offset.

Share this post


Link to post
Share on other sites
valid resource and row offset? Do you mean that the variables i'm calling are incorrect? because they're in my database under the correct albums!

Share this post


Link to post
Share on other sites
If PHP is complaining about parameter count, then it's probably right... make sure you're passing what it's expecting.

Share this post


Link to post
Share on other sites

×

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.