This is a discussion on mysql_fetch_array(): within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Newbie, having to learn as I go. Our web server started spitting out this error: Warning: mysql_fetch_array(): supplied argument is ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Newbie, having to learn as I go.
Our web server started spitting out this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /httpdocs/ticky.php on line 3 Here's the first three lines of that "ticky.php" 1: <? 2: global $headlines; 3: while ( $row = mysql_fetch_array($headlines) ) I don't understand why this would spit out an error. Do i need to declare $row variable in this doc? |
|
|||
|
Brandons of mass destruction wrote:
> Newbie, having to learn as I go. > > Our web server started spitting out this error: > > Warning: mysql_fetch_array(): supplied argument is not a valid MySQL > result resource in /httpdocs/ticky.php on line 3 > > Here's the first three lines of that "ticky.php" > > 1: <? > 2: global $headlines; > 3: while ( $row = mysql_fetch_array($headlines) ) > > I don't understand why this would spit out an error. Do i need to > declare $row variable in this doc? The warning is telling you that the argument to mysql_fetch_array() is not valid, i.e. $headlines. Where is $headlines being initialised? -- Oli |
|
|||
|
Brandons of mass destruction wrote:
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL > result resource in /httpdocs/ticky.php on line 3 > > Here's the first three lines of that "ticky.php" > > 1: <? > 2: global $headlines; > 3: while ( $row = mysql_fetch_array($headlines) ) > > I don't understand why this would spit out an error. Do i need to > declare $row variable in this doc? Try mysql_error() before and after the query. C. |
|
|||
|
In article <4hGMd.99$8r3.49@newsfe5-win.ntli.net>,
Oli Filth <oli_filth@eatspam.coldmail.com> wrote: > Brandons of mass destruction wrote: > > Newbie, having to learn as I go. > > > > Our web server started spitting out this error: > > > > Warning: mysql_fetch_array(): supplied argument is not a valid MySQL > > result resource in /httpdocs/ticky.php on line 3 > > > > Here's the first three lines of that "ticky.php" > > > > 1: <? > > 2: global $headlines; > > 3: while ( $row = mysql_fetch_array($headlines) ) > > > > I don't understand why this would spit out an error. Do i need to > > declare $row variable in this doc? > > The warning is telling you that the argument to mysql_fetch_array() is > not valid, i.e. $headlines. Where is $headlines being initialised? Background info: I'm a newbie, trying to parse code written by someone else. I thought headlines was being initialized on line 2, but it appears that I'm wrong. I guess it's merely being declared on line 2? Do I need to reinitialize it in ticky.php? |
|
|||
|
Brandons of mass destruction wrote:
> In article <4hGMd.99$8r3.49@newsfe5-win.ntli.net>, > Oli Filth <oli_filth@eatspam.coldmail.com> wrote: > > >>Brandons of mass destruction wrote: >> >>>Newbie, having to learn as I go. >>> >>>Our web server started spitting out this error: >>> >>>Warning: mysql_fetch_array(): supplied argument is not a valid MySQL >>>result resource in /httpdocs/ticky.php on line 3 >>> >>>Here's the first three lines of that "ticky.php" >>> >>>1: <? >>>2: global $headlines; >>>3: while ( $row = mysql_fetch_array($headlines) ) >>> >>>I don't understand why this would spit out an error. Do i need to >>>declare $row variable in this doc? >> >>The warning is telling you that the argument to mysql_fetch_array() is >>not valid, i.e. $headlines. Where is $headlines being initialised? > > > Background info: I'm a newbie, trying to parse code written by someone > else. > > I thought headlines was being initialized on line 2, but it appears that > I'm wrong. I guess it's merely being declared on line 2? > > Do I need to reinitialize it in ticky.php? The "global" keyword is used inside functions to access a global variable. In global scope (i.e. outside of all functions), the "global" keyword has no purpose. So yup, you need to make sure $headlines contains a valid MySQL resource ID (generally obtained by performing mysql_query("...")); -- Oli |
|
|||
|
In article <ctvg9i$bbu$2$8302bc10@news.demon.co.uk>,
Colin McKinnon <colin.deletethis@andthis.mms3.com> wrote: > Brandons of mass destruction wrote: > > > > Warning: mysql_fetch_array(): supplied argument is not a valid MySQL > > result resource in /httpdocs/ticky.php on line 3 > > > > Here's the first three lines of that "ticky.php" > > > > 1: <? > > 2: global $headlines; > > 3: while ( $row = mysql_fetch_array($headlines) ) > > > > I don't understand why this would spit out an error. Do i need to > > declare $row variable in this doc? > > Try mysql_error() before and after the query. Note quite sure how to do that, so I added this echo mysql_errno($headlines) . ": " . mysql_error($headlines). "\n"; after line 3 and got the following errors: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 3 Notice: Undefined variable: tickerlogo in /home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 12 Notice: Undefined variable: section in /home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 12 Notice: Undefined variable: siteaddress in /home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 13 Notice: Undefined variable: siteaddress in /home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 19 Notice: Undefined variable: section_link in /home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 19 |
|
|||
|
On Fri, 04 Feb 2005 08:22:50 -0500, Brandons of mass destruction <junkie46@comcast.net> wrote in 30 Lines :
>In article <4hGMd.99$8r3.49@newsfe5-win.ntli.net>, > Oli Filth <oli_filth@eatspam.coldmail.com> wrote: > >> Brandons of mass destruction wrote: >> > Newbie, having to learn as I go. >> > >> > Our web server started spitting out this error: >> > >> > Warning: mysql_fetch_array(): supplied argument is not a valid MySQL >> > result resource in /httpdocs/ticky.php on line 3 >> > >> > Here's the first three lines of that "ticky.php" >> > >> > 1: <? >> > 2: global $headlines; >> > 3: while ( $row = mysql_fetch_array($headlines) ) >> > >> > I don't understand why this would spit out an error. Do i need to >> > declare $row variable in this doc? >> >> The warning is telling you that the argument to mysql_fetch_array() is >> not valid, i.e. $headlines. Where is $headlines being initialised? > >Background info: I'm a newbie, trying to parse code written by someone >else. > >I thought headlines was being initialized on line 2, but it appears that >I'm wrong. I guess it's merely being declared on line 2? > >Do I need to reinitialize it in ticky.php? So if I read it well, $headlines is a result on another page with a mysql_query() Something like this $headline = mysql_query("QUERY") or die ("Bad Query") This is the first place that you initialize $headlines. I rather use $_SESSION variable, more easy to use. The only thing that you than don't must forget is to put realy on the beginning of the new page session_start(); Pieter [NL] |
|
|||
|
On Fri, 04 Feb 2005 08:36:07 -0500, Brandons of mass destruction <junkie46@comcast.net> wrote in 44 Lines :
>In article <ctvg9i$bbu$2$8302bc10@news.demon.co.uk>, > Colin McKinnon <colin.deletethis@andthis.mms3.com> wrote: > >> Brandons of mass destruction wrote: >> >> >> > Warning: mysql_fetch_array(): supplied argument is not a valid MySQL >> > result resource in /httpdocs/ticky.php on line 3 >> > >> > Here's the first three lines of that "ticky.php" >> > >> > 1: <? >> > 2: global $headlines; >> > 3: while ( $row = mysql_fetch_array($headlines) ) >> > >> > I don't understand why this would spit out an error. Do i need to >> > declare $row variable in this doc? >> >> Try mysql_error() before and after the query. > >Note quite sure how to do that, so I added this > >echo mysql_errno($headlines) . ": " . mysql_error($headlines). "\n"; > >after line 3 and got the following errors: > >Warning: mysql_fetch_array(): supplied argument is not a valid MySQL >result resource in >/home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 3 > >Notice: Undefined variable: tickerlogo in >/home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 12 > >Notice: Undefined variable: section in >/home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 12 > >Notice: Undefined variable: siteaddress in >/home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 13 > >Notice: Undefined variable: siteaddress in >/home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 19 > >Notice: Undefined variable: section_link in >/home/httpd/vhosts/connectsavannah.com/httpdocs/ticker.php on line 19 If I uunderstood you right, you was using somebodyelse his code. This is sometimes a problem, because the originale writer has the rest of the files. Because you try to put out 1 file for testing, you are in trouble. Try to cleanup the code with to remove all the garbage code that you don't use. Mostly what I do, is just to cut&past code that I try. Pieter [NL} |