+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Weird MYSQL_FETCH_ARRAY error

  1. #1
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Weird MYSQL_FETCH_ARRAY error

    PHP Code:
    function display_nextSession() {
       
    $today strtotime(date("m/d/y"));
       
    $sql "SELECT * FROM nextsession WHERE date>='$today' LIMIT 1";
       
    $result mysql_query($sql);
       
    $row mysql_fetch_array($result);
          
    $nextDay date("m/d/y"$row[1]);
    echo 
    $nextDay;

    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\mcs\sources\functions\home.php on line 13
    12/31/69
    For some reason, the above function works on one page, but does not work on another. I get the error shown above.

    Im first going to see if you can solve it without me having to put up the pages where the code is on, but if it is needed just reply, and I will get it up ASAP

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Weird MYSQL_FETCH_ARRAY error

    is the query returning no results?
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Weird MYSQL_FETCH_ARRAY error

    Sorry, this is quite an unusual error from what I can tell. More details may be necessary. I recommend switching to the mysqli family of functions.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Weird MYSQL_FETCH_ARRAY error

    You code produces:

    $sql == "SELECT * FROM nextsession WHERE date>='1253077200' LIMIT 1"

    What sort of field is 'date' ? Did you store it as a INT? I believe mySQL stores the 'Date' type in YYYY-MM-DD format, not as a UNIX time. Since 'Timestamp' has the UNIX date range, that might be ok.
    Nothing is always absolutely so.

  5. #5
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Weird MYSQL_FETCH_ARRAY error

    Quote Originally Posted by garrettroyce View Post
    is the query returning no results?
    I did var_dump(result); and got bool(false)

    Quote Originally Posted by descalzo View Post
    You code produces:

    $sql == "SELECT * FROM nextsession WHERE date>='1253077200' LIMIT 1"

    What sort of field is 'date' ? Did you store it as a INT? I believe mySQL stores the 'Date' type in YYYY-MM-DD format, not as a UNIX time. Since 'Timestamp' has the UNIX date range, that might be ok.
    it is an INT(11). what do you suggest I do?
    Last edited by diabolo; 09-17-2009 at 05:30 AM.

  6. #6
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Weird MYSQL_FETCH_ARRAY error

    your query is failing if $result == false
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  7. #7
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Weird MYSQL_FETCH_ARRAY error

    ..deleted bad suggestion...

    ...Edit to add:

    Below is what you want. Since $result is not a resource, it is because of an error, not because the query returned no results.
    Last edited by descalzo; 09-17-2009 at 02:01 PM.
    Nothing is always absolutely so.

  8. #8
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Weird MYSQL_FETCH_ARRAY error

    I would implement some error checking:

    Code:
    $result = mysql_query(.....); //your query goes here :P
    if (!$result) {
      die(mysql_error());
    }
    if (mysql_num_rows($result) == 0) { //no rows match!
    //do something else
    }
    else {
    //now do what you were originally doing
    }
    Just make sure you get rid of the die(mysql_error()) part and handle it more gracefully when you go into launching your site so users don't get nasty errors.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  9. #9
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Weird MYSQL_FETCH_ARRAY error

    I followed what garrettroyce said,
    and it gave me this error:

    No Database Selected.

    Let me explain something first:
    It works on the user end. But in the admin end I get a problem. The admin header includes the user header, but it just has a little extra code for the administrative actions. So technically if the user end can establish a connection, shouldn't the admin area be able too?

  10. #10
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Weird MYSQL_FETCH_ARRAY error

    Without seeing all the code, I have no idea.

    By the way, my car won't start. Can you tell me why?
    Last edited by descalzo; 09-17-2009 at 02:55 PM.
    Nothing is always absolutely so.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Weird phpBB3 error
    By z_killemall in forum Programming Help
    Replies: 4
    Last Post: 04-16-2009, 08:27 PM
  2. Replies: 3
    Last Post: 09-08-2008, 09:13 PM
  3. Error en mi host
    By roonline in forum Soporte
    Replies: 17
    Last Post: 11-14-2007, 03:28 PM
  4. 500 Internal Server Error (PHP Error?)
    By aniklaus in forum Free Hosting
    Replies: 3
    Last Post: 11-12-2007, 11:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers