rich_greeny Posted September 14, 2006 Share Posted September 14, 2006 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 14, 2006 Share Posted September 14, 2006 Well, you're using mysql_fetch_array(), so you get back an array... I guess you'd probably want to use mysql_result() instead. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted September 14, 2006 Share Posted September 14, 2006 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] Quote Link to comment Share on other sites More sharing options...
rich_greeny Posted September 14, 2006 Author Share Posted September 14, 2006 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? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 14, 2006 Share Posted September 14, 2006 Check the refman... must be parameter order, or something similar. Quote Link to comment Share on other sites More sharing options...
rich_greeny Posted September 14, 2006 Author Share Posted September 14, 2006 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! Quote Link to comment Share on other sites More sharing options...
fenway Posted September 14, 2006 Share Posted September 14, 2006 The posted example should work just fine... all you need to specify is a valid resource and a row offset. Quote Link to comment Share on other sites More sharing options...
rich_greeny Posted September 15, 2006 Author Share Posted September 15, 2006 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! Quote Link to comment Share on other sites More sharing options...
fenway Posted September 15, 2006 Share Posted September 15, 2006 If PHP is complaining about parameter count, then it's probably right... make sure you're passing what it's expecting. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.