#1
  1. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    I am using this code to get some data from a mySQL database. Which seems pefectly valid to me. Here it is:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    <?

    MYSQL_CONNECT("localhost", "user", "pass");
    @MYSQL_SELECT_DB(db);

    $new = date("U") - 2592000;

    $query = "SELECT * FROM noticeboard WHERE (reply = no) AND (id > $new) ORDER BY id DESC";

    $result = MYSQL_QUERY($query);

    while ($row = MYSQL_FETCH_ARRAY($results)) {

    $title = $row["title"];
    $author = $row["author"];
    $date = $row["date"];
    $replies = $row["replies"];

    echo " <tr>n";
    echo " <td bgcolor="#99CCFF" width="55%">n";
    echo " <font size="2" face="Arial, Helvetica, sans-serif">n";
    echo " <a href="noticeboard.php3?cmd=show&id=$id">$title</a>n";
    echo " </font>n";
    echo " </td>n";
    echo " <td bgcolor="#EBF5FF"><font size="2" face="Arial, Helvetica, sans-serif">$author</font></td>n";
    echo " <td bgcolor="#EBF5FF"><font size="2" face="Arial, Helvetica, sans-serif">$date</font></td>n";
    echo " <td bgcolor="#EBF5FF"><div align="center"><font size="2" face="Arial, Helvetica, sans-serif">$replies</font></div>n";
    echo " </td>n";
    echo " </tr>nn";

    }

    MYSQL_CLOSE();

    ?>

    [/code]

    However when I try and run this code I get this stupid message:

    Warning: 0 is not a MySQL result index in /usr/users/g25n36rj/public_html/nb/noticeboard.php3 on line 469

    Line 469 is this:

    while ($row = MYSQL_FETCH_ARRAY($results)) {

    SO WHAT IS WRONG????????????

    Please help before I lose my head! Its stupid pointless little errors like this in code that i KNOW is correct that make me lose my faith in programming!!!!!

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  2. #2
  3. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2000
    Location
    Enschede, The Netherlands
    Posts
    1,527
    Rep Power
    16
    If I'm not mistaken there can be several things that can go wrong:

    1) The query results an empty result which you try to fetch.. I'd use the following to prevent such an error to show:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>
    if ( $result=mysql_fetch_array($result)) {
    do {
    }
    while( $result=mysql_fetch_array($result));
    }
    else{
    print( "Result is empty" );
    }
    [/quote]

    2) the query itself is not valid? I'm not sure mysql likes brackets (don't use them myself to be honest) and sometimes I put single quotes around a variable to make sure it's a string: '$new' (not sure either if that's necesarry )

    3) maybe you have some of the names wrong? I had once the same problem and after a while I discovered I hadn't changed the name of a column after copy-pasting it from another page... just a suggestion

    finally, why do you have a '@' in front of the second line???

    Hope this helps..

    Mirax

    [This message has been edited by Mirax (edited September 08, 2000).]
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    That means that mysql returned 0 for a result index which indicates an error in your query.

    Quick glance: You need quotes- reply='no'
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,646
    Rep Power
    4492
    if you put echo mysql_error(); after your attempt at an SQL statement, it'll give you a more exact error message. it's very helpful.

    ---John Holmes...
  8. #5
  9. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    Thanks everyone, I needed the quotes and to make sure that all the conditionals were met, which I wasn't doing.

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    UK
    Posts
    7
    Rep Power
    0
    line 469 is building the array based on $results

    Line 468 declares $result (NO s) and populates it from the query

Similar Threads

  1. Highlight search result from mysql database search
    By Gurt in forum PHP Development
    Replies: 3
    Last Post: February 17th, 2004, 03:39 AM
  2. Problem: Displaying image link inside table from MySQL
    By Shadowz in forum PHP Development
    Replies: 4
    Last Post: February 13th, 2004, 01:37 AM
  3. DreamWeaver MX and MySQL problem!!
    By genog in forum MySQL Help
    Replies: 3
    Last Post: February 12th, 2004, 06:57 AM
  4. MySQL lock tables problem: mysql hangs?
    By Cyclefreak in forum MySQL Help
    Replies: 0
    Last Post: February 6th, 2004, 07:24 AM
  5. mysql problem with joining tables , complicated!
    By toxical in forum PHP Development
    Replies: 6
    Last Post: January 27th, 2004, 03:43 PM

IMN logo majestic logo threadwatch logo seochat tools logo