XeroXer Posted December 27, 2006 Share Posted December 27, 2006 I am creating a small simple forum and this confuses me.This I do:[code]<?phpinclude("config/database.php");$con = mysql_connect("$mysqlhost","$mysqlusr","$mysqlpass") or die('Could not connect: ' . mysql_error());mysql_select_db($db_name, $con);$results = mysql_query("SELECT * FROM v2_forum_cat ORDER BY id");while($row = mysql_fetch_array($result)){echo "<table border='0' cellspacing='0' cellpadding='0'>";echo "<tr><td>";echo $row['name'];echo "</td></tr>";echo "<tr><td><span class='smalltxt'>";echo $row['descr'];echo "</span></td></tr>";echo "</table>";}mysql_close($con);?>[/code]This output I get:[list][*][b]Warning:[/b] mysql_fetch_array(): supplied argument is not a valid MySQL result resource in[b]/customers/xeroxer.com/xeroxer.com/httpd.www/v2/forum.php[/b] on line [b]16[/b][/list] Quote Link to comment Share on other sites More sharing options...
fert Posted December 27, 2006 Share Posted December 27, 2006 change[code]mysql_select_db($db_name, $con);$results = mysql_query("SELECT * FROM v2_forum_cat ORDER BY id");[/code]to[code]@mysql_select_db($db_name, $con) or die(mysql_error());$results = @mysql_query("SELECT * FROM v2_forum_cat ORDER BY id") or die(mysql_error());[/code] Quote Link to comment Share on other sites More sharing options...
XeroXer Posted December 27, 2006 Author Share Posted December 27, 2006 Still the same error.Doesn't my webserver support the mysql_fetch_array command? Quote Link to comment Share on other sites More sharing options...
trq Posted December 27, 2006 Share Posted December 27, 2006 it meens your query is failing. You should allways check your query was successfull before trying to use the result from it.Also, while developing avoid using the @ error supressor. Quote Link to comment Share on other sites More sharing options...
XeroXer Posted December 27, 2006 Author Share Posted December 27, 2006 Why would it fail?I use the same connect info to insert user info into the user table and that works.But printing out doesn't work.. Quote Link to comment Share on other sites More sharing options...
bljepp69 Posted December 27, 2006 Share Posted December 27, 2006 You've just missed a little on your variables. You have this:[code]$results = mysql_query("SELECT * FROM v2_forum_cat ORDER BY id");while($row = mysql_fetch_array($result))[/code]You define '$results' but then call '$result' -- $result is empty so the query fails. Quote Link to comment Share on other sites More sharing options...
XeroXer Posted December 27, 2006 Author Share Posted December 27, 2006 thx a lot bljepp69.That was the miss and now it works... Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 28, 2006 Share Posted December 28, 2006 I thort that you dont need mysql_close() only if using pconnect dont no anyone? Quote Link to comment Share on other sites More sharing options...
Stopofeger Posted December 28, 2006 Share Posted December 28, 2006 Different variable name used.also, Use mysql_fetch_assoc() not mysql_fetch_array().the second one returns indexed arrays. And needs a flag to be given in order to return Associative array.its better to use fetch_assoc. 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.