Professional Web Applications Themes

mysql_fetch_array - PHP Development

<?php echo "HI " . $name; $result = mysql_query("SELECT * FROM album WHERE username='{$name}'"); while ($next_row = mysql_fetch_array($result)) { $album_name = $next_row['name']; echo "<a href=\"main.php?album=$album_name\"><font size=\"+1\" color=\"#FFFFFF\"> $album_name </font></a><br/>"; } ?> This gives me a Warning that mysql_fetch_array isn't getting a valid MySQL resource, but it has the right value in $name and doesn't have an obvious problem, any debugging insight? Thanks, RG...

  1. #1

    Default mysql_fetch_array

    <?php
    echo "HI " . $name;
    $result = mysql_query("SELECT * FROM album WHERE username='{$name}'");

    while ($next_row = mysql_fetch_array($result)) {
    $album_name = $next_row['name'];

    echo "<a href=\"main.php?album=$album_name\"><font size=\"+1\"
    color=\"#FFFFFF\">

    $album_name

    </font></a><br/>";
    }
    ?>

    This gives me a Warning that mysql_fetch_array isn't getting a valid MySQL
    resource, but it has the right value in $name and doesn't have an obvious
    problem, any debugging insight?

    Thanks,
    RG


    Robert Guest

  2. #2

    Default Re: mysql_fetch_array

    Robert <gtg463gmail.gatech.edu> wrote:
    > $result = mysql_query("SELECT * FROM album WHERE username='{$name}'");
    > while ($next_row = mysql_fetch_array($result)) {
    [snip]
    > }
    > ?>
    Is this the entire script you are using?
    > This gives me a Warning that mysql_fetch_array isn't getting a valid MySQL
    > resource, but it has the right value in $name and doesn't have an obvious
    > problem, any debugging insight?
    YOu'r not checking if the query returns a valid response. Implement some
    flow control: eg replace the $result line with:

    $result=..........'{$name}'") or die(mysql_error());

    And that might give you a usefull hint (like the fact that you forgot to
    open a connection to a database).

    --

    Daniel Tryba

    Daniel Tryba Guest

  3. #3

    Default Re: mysql_fetch_array

    Robert wrote:
    > This gives me a Warning that mysql_fetch_array isn't getting a valid MySQL
    > resource, but it has the right value in $name and doesn't have an obvious
    > problem, any debugging insight?
    use error-checking.

    $sql = "select ...";
    mysql_query($sql) or die(mysql_error() . " in [$sql]");


    I couldn't recreate the error you got.


    --
    I have a spam filter working.
    To mail me include "urkxvq" (with or without the quotes)
    in the subject line, or your mail will be ruthlessly discarded.
    Pedro Guest

  4. #4

    Default Re: mysql_fetch_array


    "Daniel Tryba" <news_comp.lang.phpcanopus.nl> wrote in message
    news:bnkhu3$lcc$1news.tue.nl...
    > Robert <gtg463gmail.gatech.edu> wrote:
    > > $result = mysql_query("SELECT * FROM album WHERE username='{$name}'");
    > > while ($next_row = mysql_fetch_array($result)) {
    > [snip]
    > > }
    > > ?>
    >
    > Is this the entire script you are using?
    >
    > > This gives me a Warning that mysql_fetch_array isn't getting a valid
    MySQL
    > > resource, but it has the right value in $name and doesn't have an
    obvious
    > > problem, any debugging insight?
    >
    > YOu'r not checking if the query returns a valid response. Implement some
    > flow control: eg replace the $result line with:
    >
    > $result=..........'{$name}'") or die(mysql_error());
    >
    > And that might give you a usefull hint (like the fact that you forgot to
    > open a connection to a database).
    >
    > --
    >
    > Daniel Tryba
    >
    I was connecting, it was a selection problem. Thanks guys.


    Robert Guest

  5. #5

    Default mysql_fetch_array

    I set up phpmyadmin, and it works fine, but my code isn't working. id is
    the correct column (it is the primary key), stock is the correct database.

    CODE:
    $qresult = mysql_query("SELECT id FROM 'stock'");
    echo ("START<P><HR>");
    while ($row = mysql_fetch_array($qresult)) {
    echo ($row ["name"]);
    echo ("<br>");
    }
    echo ("<P><HR><P>END");

    OUTPUT:
    START
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
    result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 14
    END

    does anybody have any idea's why?
    Matthew Robinson Guest

  6. #6

    Default Re: mysql_fetch_array

    "Matthew Robinson" a écrit le 07/01/2004 :
    > I set up phpmyadmin, and it works fine, but my code isn't working. id is
    > the correct column (it is the primary key), stock is the correct database.
    >
    > CODE:
    > $qresult = mysql_query("SELECT id FROM 'stock'");
    > echo ("START<P><HR>");
    > while ($row = mysql_fetch_array($qresult)) {
    > echo ($row ["name"]);
    > echo ("<br>");
    > }
    > echo ("<P><HR><P>END");
    >
    > OUTPUT:
    > START
    > Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
    > result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 14
    > END
    >
    > does anybody have any idea's why?
    You'll have pb after that because you must not put space between var
    and [] : $row["name"] and not $row ["name"]
    And, the ["name"] key is not defined... only $row["id"] is avaible.
    But this does not solve your mysql_fetch_array() pb. Use mysql_error()
    to know more.

    --
    Have you read the manual ?
    [url]http://www.php.net/manual/en/[/url]

    Jedi121 Guest

  7. #7

    Default Re: mysql_fetch_array

    On Wed, 07 Jan 2004 00:24:13 +0000, Matthew Robinson
    <mattyrobinson69hotmail.com> wrote:
    >I set up phpmyadmin, and it works fine, but my code isn't working. id is
    >the correct column (it is the primary key), stock is the correct database.
    >
    >CODE:
    >$qresult = mysql_query("SELECT id FROM 'stock'");
    >Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
    >result resource in /home/houseproudlancs_co_uk/index_to_be.php on line 14
    >END
    >
    >does anybody have any idea's why?
    Ask the database, rather than ignoring it.

    $qresult = mysql_query("SELECT id FROM 'stock'")
    or die("Query failed because: " . mysql_error());

    Remove the quotes around stock; it's a table, not a literal string. Single
    quotes are for literal strings. You don't need quotes around tables or column
    identifiers.

    --
    Andy Hassall (andyandyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage ysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

  8. #8

    Default Re: mysql_fetch_array


    On 6-Jan-2004, Jedi121 <jedi121newsfree.fr.Removethis> wrote:
    > You'll have pb after that because you must not put space between var
    > and [] : $row["name"] and not $row ["name"]
    Where did you get this?? The space between $row and [] is allowed.
    > Have you read the manual ?
    > [url]http://www.php.net/manual/en/[/url]
    Good advise, have you?


    --
    Tom Thackrey
    [url]www.creative-light.com[/url]
    tom (at) creative (dash) light (dot) com
    do NOT send email to [email]jamesbutlerwillglen.net[/email] (it's reserved for spammers)
    Tom Thackrey Guest

  9. #9

    Default Re: mysql_fetch_array

    "Tom Thackrey" a écrit le 07/01/2004 :
    > Where did you get this?? The space between $row and [] is allowed.
    Oups, you're right I should have checked this before...
    My apologies.
    >> Have you read the manual ?
    >> [url]http://www.php.net/manual/en/[/url]
    >
    > Good advise, have you?
    Yes, I try to refer to it as often as possible.

    --
    Have you read the manual ?
    [url]http://www.php.net/manual/en/[/url]

    Jedi121 Guest

Similar Threads

  1. Replies: 1
    Last Post: May 2nd, 03:26 AM
  2. resetting mysql_fetch_array()
    By jg in forum PHP Development
    Replies: 1
    Last Post: April 5th, 07:19 PM
  3. problems with mysql_fetch_array in 2D array
    By Kevin Torr in forum PHP Development
    Replies: 6
    Last Post: February 13th, 10:27 PM
  4. Replies: 0
    Last Post: October 27th, 11:36 AM
  5. #25998 [NEW]: mysql_fetch_array display nothing over 530 records
    By hsutanto78 at hotmail dot com in forum PHP Development
    Replies: 0
    Last Post: October 27th, 09:17 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