Results 1 to 5 of 5

Thread: What am I doing wrong? [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    131

    Resolved What am I doing wrong? [RESOLVED]

    Why am I getting the error:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/b/i/k/mydirectory/html/ax0!calRe367/view.php on line 13

    but it still shows me the data underneath it


    VB Code:
    1. <?php
    2. include("cn.php");
    3. include("commonview.php");
    4. checklogin();
    5.  
    6. $sql = "SELECT * FROM calendar";
    7. $calendar = mysql_query($sql) or die(mysql_error());
    8.  
    9.  
    10. echo '<table>
    11.     <tr>';
    12.  
    13. while ($calendar = mysql_fetch_array($calendar)) {
    14.  
    15.     if ($i == 2) {
    16.         echo '</tr><tr>';
    17.         $i = 0;
    18.     }
    19.  
    20.     echo '<td><b>' . $calendar['dept'] . '</b><br>';
    21.     echo $calendar['mon'] . '<br>';
    22.     echo $calendar['tues'] . '<br>';
    23.     echo $calendar['wed'] . '<br>';
    24.     echo $calendar['thurs'] . '<br>';
    25.     echo $calendar['fri'] . '<br>';
    26.     echo $calendar['sat'] . '<br>';
    27.     echo $calendar['sun'] . '<br><br></td>';
    28.  
    29.     $i++;
    30. }
    31.  
    32. echo '</tr></table><br>';
    33.  
    34. ?>
    Last edited by espylacopa; May 24th, 2005 at 04:51 PM.
    Things fall apart which the center cannot hold...

  2. #2
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Re: What am I doing wrong?

    I've had this before when the SQL statement was incorrect (i.e. DELEE instead of DELETE).
    Possibly, is it because your database doesn't have a table called 'calendar', that's the only thing i can think of. That errors usually tends to mean incorrect sql statement.
    sql_lall

  3. #3
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: What am I doing wrong?

    well, correct my if i am wrong, but shouldnt
    PHP Code:
    while ($calendar mysql_fetch_array($calendar)) { 
    be:
    PHP Code:
    while ($calendar == mysql_fetch_array($calendar)) { 
    ???
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: What am I doing wrong?

    $calendar first stores a reference to the result of the query. The statement $calendar = mysql_fetch_array($calendar) overwrites this reference. Hence, the next time it loops, it fails because $calendar no longer contains a reference to the result of the query, it contains an array.

    To solve this change the name of the variable. I.e:
    PHP Code:
    $resultmysql_query($sql) or die(mysql_error());

    /* other code */

    while ($calendarmysql_fetch_array($result)) { 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    131

    Re: What am I doing wrong?

    thanks visual ad. I am used to asp, but the server doesnt support it. It worked great.
    Things fall apart which the center cannot hold...

Posting Permissions

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



Click Here to Expand Forum to Full Width