mysql_fetch_array():

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


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-04-2005
Brandons of mass destruction
 
Posts: n/a
Default mysql_fetch_array():

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?
Reply With Quote
  #2 (permalink)  
Old 02-04-2005
Oli Filth
 
Posts: n/a
Default Re: mysql_fetch_array():

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
Reply With Quote
  #3 (permalink)  
Old 02-04-2005
Colin McKinnon
 
Posts: n/a
Default Re: mysql_fetch_array():

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.
Reply With Quote
  #4 (permalink)  
Old 02-04-2005
Brandons of mass destruction
 
Posts: n/a
Default Re: mysql_fetch_array():

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?
Reply With Quote
  #5 (permalink)  
Old 02-04-2005
Oli Filth
 
Posts: n/a
Default Re: mysql_fetch_array():

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
Reply With Quote
  #6 (permalink)  
Old 02-04-2005
Brandons of mass destruction
 
Posts: n/a
Default Re: mysql_fetch_array():

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
Reply With Quote
  #7 (permalink)  
Old 02-04-2005
Pieter
 
Posts: n/a
Default Re: mysql_fetch_array():

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]
Reply With Quote
  #8 (permalink)  
Old 02-04-2005
Pieter
 
Posts: n/a
Default Re: mysql_fetch_array():

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}

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:20 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0