www.webdeveloper.com
Results 1 to 5 of 5

Thread: mysql_fetch_array not valid mysql result

  1. #1
    Join Date
    Jun 2011
    Posts
    14

    Unhappy mysql_fetch_array not valid mysql result

    Hey,

    I have a problem:

    I have this code in my website:
    PHP Code:
    <?php

    $jaar 
    $_GET["jaar"];

    echo 
    "<div id='header'>Vriendengroep Oerdegelijk | ".$jaar."</div>";
    echo 
    "<div id='main'>";

    mysql_connect("fdb3.agilityhoster.com","784975_years","oerdegelijk");
    mysql_select_db("784975_years");

    $sql mysql_query("SELECHT * FROM jaren
    WHERE jaar=
    $jaar");
    $result mysql_query("SELECT count(*) as bestaat FROM jaren WHERE jaar=$jaar");
    $rij mysql_fetch_assoc($result);

    if(
    $rij['bestaat'] != 1){
    echo 
    "Over het jaar ".$jaar." is nog geen informatie beschikbaar.";
    } else {
    while(
    $row mysql_fetch_array($sql)){
    echo 
    "Datum: ".$row['datum'];
    }
    }
    echo 
    "</div>";
    ?>
    What I want the code to do is to check in the database if there's a row with the year(jaar) as the variable $jaar, when it does it has to

    PHP Code:
    echo "Over het jaar ".$jaar." is nog geen informatie beschikbaar."
    and else it has to give the date that's in the same row as the year.

    But I continue getting this error:

    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /srv/disk7/784975/www/oerdegelijk.agilityhoster.com/jaren.html on line 33
    Can anyone explain me what I'm doing wrong, and give the solution?

    p.s. I'm dutch, so when you need any translations, just say.

  2. #2
    Join Date
    Jul 2011
    Posts
    8

    The solution

    You must see the line 33 of your script.

    I asume that is

    "$sql = mysql_query("SELECHT * FROM jaren
    WHERE jaar=$jaar"); "

    if you see, you write SELECHT and the correct statement es SELECT

    Best Regards.

    Martin Mantaras

  3. #3
    Join Date
    Jun 2011
    Posts
    14
    Oh my god... That's imbarissing Thanx a lot!

  4. #4
    Join Date
    Jul 2011
    Posts
    8
    In the other hand.
    I see you need know the num of records (in the next line)
    This can be obtaining with the mysql_num_rows function.

    http://php.net/manual/en/function.mysql-num-rows.php

    Best Regards again.

  5. #5
    Join Date
    Jul 2011
    Posts
    8
    Applying the last comment.
    Your code can't be

    <?php

    $jaar = $_GET["jaar"];

    echo "<div id='header'>Vriendengroep Oerdegelijk | ".$jaar."</div>";
    echo "<div id='main'>";

    mysql_connect("fdb3.agilityhoster.com","784975_years","oerdegelijk");

    mysql_select_db("784975_years");

    if($jaar!="")
    {
    $sql = mysql_query("SELECT * FROM jaren WHERE jaar=".$jaar);
    $numofrecords=mysql_num_rows($sql);
    if($numofrecords == 0)
    {
    echo "Over het jaar ".$jaar." is nog geen informatie beschikbaar.";
    } else {
    while($row = mysql_fetch_array($sql)){
    echo "Datum: ".$row['datum'];
    }
    }
    }
    echo "</div>";
    ?>


    Best Regards again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles