Jump to content


Photo

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


  • Please log in to reply
8 replies to this topic

#1 rich_greeny

rich_greeny
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 14 September 2006 - 06:32 PM

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?


<?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(); 

?>

Thanks in advance.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 14 September 2006 - 07:01 PM

Well, you're using mysql_fetch_array(), so you get back an array... I guess you'd probably want to use mysql_result() instead.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 14 September 2006 - 07:03 PM

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:-
$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


put those in place of your two lines
$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'"));

you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource

#4 rich_greeny

rich_greeny
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 14 September 2006 - 07:28 PM

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?

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 14 September 2006 - 07:30 PM

Check the refman... must be parameter order, or something similar.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#6 rich_greeny

rich_greeny
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 14 September 2006 - 07:44 PM

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!

#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 14 September 2006 - 08:09 PM

The posted example should work just fine... all you need to specify is a valid resource and a row offset.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#8 rich_greeny

rich_greeny
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 15 September 2006 - 11:31 AM

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!

#9 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 15 September 2006 - 12:49 PM

If PHP is complaining about parameter count, then it's probably right... make sure you're passing what it's expecting.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users