Jump to content

[SOLVED] mysql_fetch_array


XeroXer

Recommended Posts

I am creating a small simple forum and this confuses me.

This I do:
[code]<?php
include("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

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]
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.

Archived

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

×
×
  • Create New...

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.