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
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]
Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.