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] Link to comment https://forums.phpfreaks.com/topic/32003-solved-mysql_fetch_array/ 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] Link to comment https://forums.phpfreaks.com/topic/32003-solved-mysql_fetch_array/#findComment-148542 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? Link to comment https://forums.phpfreaks.com/topic/32003-solved-mysql_fetch_array/#findComment-148543 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. Link to comment https://forums.phpfreaks.com/topic/32003-solved-mysql_fetch_array/#findComment-148544 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.. Link to comment https://forums.phpfreaks.com/topic/32003-solved-mysql_fetch_array/#findComment-148547 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. Link to comment https://forums.phpfreaks.com/topic/32003-solved-mysql_fetch_array/#findComment-148548 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... Link to comment https://forums.phpfreaks.com/topic/32003-solved-mysql_fetch_array/#findComment-148549 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? Link to comment https://forums.phpfreaks.com/topic/32003-solved-mysql_fetch_array/#findComment-148650 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. Link to comment https://forums.phpfreaks.com/topic/32003-solved-mysql_fetch_array/#findComment-148654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.