Professional Web Applications Themes

mysql_fetch_array(): - PHP Development

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

  1. #1

    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?
    Brandons Guest

  2. #2

    Default Re: mysql_fetch_array():

    Brandons of mass destruction wrote: 

    The warning is telling you that the argument to mysql_fetch_array() is
    not valid, i.e. $headlines. Where is $headlines being initialised?

    --
    Oli
    Oli Guest

  3. #3

    Default Re: mysql_fetch_array():

    Brandons of mass destruction wrote:

     

    Try mysql_error() before and after the query.

    C.
    Colin Guest

  4. #4

    Default Re: mysql_fetch_array():

    In article <4hGMd.99$ntli.net>,
    Oli Filth <coldmail.com> wrote:
     
    >
    > The warning is telling you that the argument to mysql_fetch_array() is
    > not valid, i.e. $headlines. Where is $headlines being initialised?[/ref]

    Background info: I'm a newbie, trying to p 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 Guest

  5. #5

    Default Re: mysql_fetch_array():

    Brandons of mass destruction wrote: 
    >>
    >>The warning is telling you that the argument to mysql_fetch_array() is
    >>not valid, i.e. $headlines. Where is $headlines being initialised?[/ref]
    >
    >
    > Background info: I'm a newbie, trying to p 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?[/ref]

    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
    Oli Guest

  6. #6

    Default Re: mysql_fetch_array():

    In article <ctvg9i$bbu$2$demon.co.uk>,
    Colin McKinnon <mms3.com> wrote:
     
    >
    > Try mysql_error() before and after the query.[/ref]

    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
    Brandons Guest

  7. #7

    Default Re: mysql_fetch_array():

    On Fri, 04 Feb 2005 08:22:50 -0500, Brandons of mass destruction <net> wrote in 30 Lines :
     
    >>
    >> The warning is telling you that the argument to mysql_fetch_array() is
    >> not valid, i.e. $headlines. Where is $headlines being initialised?[/ref]
    >
    >Background info: I'm a newbie, trying to p 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?[/ref]

    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]
    Pieter Guest

  8. #8

    Default Re: mysql_fetch_array():

    On Fri, 04 Feb 2005 08:36:07 -0500, Brandons of mass destruction <net> wrote in 44 Lines :
     
    >>
    >> Try mysql_error() before and after the query.[/ref]
    >
    >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[/ref]

    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}

    Pieter Guest

Similar Threads

  1. resetting mysql_fetch_array()
    By jg in forum PHP Development
    Replies: 1
    Last Post: April 5th, 07:19 PM
  2. mysql_fetch_array
    By Robert in forum PHP Development
    Replies: 8
    Last Post: January 7th, 08:09 AM
  3. mysql_fetch_array problem
    By Matthew in forum PHP Development
    Replies: 15
    Last Post: January 7th, 01:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139