Jump to content


Photo

Mysql_fetch_array();


  • Please log in to reply
6 replies to this topic

#1 djcontact

djcontact
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 29 June 2006 - 07:43 PM

ok some im getting these error:


Warning: mysql_fetch_array(): 20 is not a valid MySQL result resource in /home/nelsona/public_html/index.php on line 9

Warning: mysql_free_result(): 20 is not a valid MySQL result resource in /home/nelsona/public_html/index.php on line 17

any idea why im perhaps getting this error...

i first did this site on my server and had no problems,
then transfered it over to the clients server and now im getting this error.

any help would be appricated

thanks
djcontact

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 June 2006 - 08:08 PM

You usually get this error message when you have an error in your sql query. Please read [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95376\" target=\"_blank\"]this thread[/a]. Also seardch the forum too as this question has been answered many times over

#3 djcontact

djcontact
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 29 June 2006 - 08:40 PM

so i read that thread you suggested [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95376\" target=\"_blank\"]Invalid Resource, MySQL[/a] and it doesnt really answer my question...
either that or im just not understanding it...

i also went ahead and did a search for mysql_fetch_array and i did get a hand full of search results but nothing that i can relate too...

well with the amount of php knowledege that i know which is not much, i would love to get some assistants on this.

thanks again
djcontact

#4 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 29 June 2006 - 08:42 PM

and how are your mysql queries set up for error checking?? here is a simple and reliable way to do error trapping with MySQL:

$result = mysql_query("SELECT * FROM TABLE WHERE blah='$blah'") or die("MySQL Query failed:  ".mysql_error());

the mysql_error() function will allow you to get the error reported by MySQL

#5 djcontact

djcontact
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 29 June 2006 - 08:51 PM

this is what i have on my connection.php
#database access info
define ('DB_USER', 'myuser');
define ('DB_PASS', 'mypass');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'mydbname');

#database connection
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASS) OR die ('Could not connect to mysql: ' .mysql_error() );
mysql_select_db (DB_NAME) OR die ('Could not select database: ' .mysql_error() );


and this is my index.php
include ('_include/connect.php');
//make query
$query = "SELECT * FROM layout";
//run the query
$result = @mysql_query ($query);

if ($result) {
    //fetch
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        if($row[0] == 1) {
            include ('layout_01.php');
        }
        if($row[0] == 2) {
            include ('layout_02.php');
        }
    }
    mysql_free_result ($result); //free up the resources
} else { //if it did not run ok
    echo '<p>The content could not be displayed due to system error!</p>';
}


#6 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 29 June 2006 - 08:54 PM

so you need to add some error checking for your MySQL statement like i already posted. change your code to look like this:

include ('_include/connect.php');
//make query
$query = "SELECT * FROM layout";
//run the query
$result = @mysql_query ($query) or die("MySQL query failed:  ".mysql_error());

if ($result) {
    //fetch
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        if($row[0] == 1) {
            include ('layout_01.php');
        }
        if($row[0] == 2) {
            include ('layout_02.php');
        }
    }
    mysql_free_result ($result); //free up the resources
} else { //if it did not run ok
    echo '<p>The content could not be displayed due to system error!</p>';
}


#7 djcontact

djcontact
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 29 June 2006 - 09:11 PM

ok so i added the error checking for the mysql statement but im still getting the same error,

Warning: mysql_fetch_array(): 20 is not a valid MySQL result resource in /home/nelsona/public_html/index.php on line 9

Warning: mysql_free_result(): 20 is not a valid MySQL result resource in /home/nelsona/public_html/index.php on line 17



i really appricate the help
thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users