Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default MySql query help

    Hey,

    I am trying to retrive information from a database using the
    'Mysql_fetch_assoc' function, but the problem is.. it is just
    one row of data from the table, not an array, so it generates an
    error. What function do u use/ What do i need to do to just get that
    one row?

    thankx.

    // error
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
    result resource in ********* on line 23
    //

    <!-- my code segment !-->
    <?
    query = "SELECT * FROM users WHERE user =
    'user' LIMIT 1";
    result = mysql_query(query);
    record = mysql_fetch_assoc(query);
    {
    fname = record["fname"];
    lname = record["lname"];
    mname = record["mname"];
    position = record["position"];
    }
    ?>
    <!-- end my code-->




    ----------------------------------------
    The post originated from PHP Freaks:
    ----------------------------------------
    [url]http://www.phpfreaks.com[/url]
    [url]http://www.phpfreaks.com/forums[/url]


    luckyrye Guest

  2. Similar Questions and Discussions

    1. Is this a MySQL Query bug?
      I wrote a SQL script in MySQL Query, and saved it as script.sql, but when I executed it in windows command line "mysql -h localhost -u root...
    2. MySQL Query Cache Not Working: MySQL 5 / Windows XP
      Please excuse this post if you've already read it on mailing.database.mysql - i just discovered these other groups. future posts will be...
    3. MYSQL query: AND OR?
      This will probably sound stupid. How would you do a MYSQL query that was to evaluate if either condition A or B was meet? And if so, in what...
    4. Query log for mySQL?
      Is there a simple way to create a query log for mySQL? I've been asked^h^h^h^h^h told to add a layer of auditing on an existing application. It's...
    5. mysql/php query
      I have a question about (i think) joining. If I have a table in a database that has this info: key - name - favorite 1 - john - 2 2 - ...
  3. #2

    Default Re: MySql query help

    luckyrye wrote:
    > I am trying to retrive information from a database using the
    > 'Mysql_fetch_assoc' function, but the problem is.. it is just
    > one row of data from the table, not an array, so it generates an
    > error. What function do u use/ What do i need to do to just get that
    > one row?
    From your example this is wrong:

    $result = mysql_query($query);
    $record = mysql_fetch_assoc($query);

    It should be like this:

    $result = mysql_query($query);
    $record = mysql_fetch_assoc($result);

    --
    Chris Hope
    The Electric Toolbox - [url]http://www.electrictoolbox.com/[/url]
    Chris Hope Guest

  4. #3

    Default Re: MySql query help

    Ooops, i get careless sometimes. sry bout that.



    ----------------------------------------
    The post originated from PHP Freaks:
    ----------------------------------------
    [url]http://www.phpfreaks.com[/url]
    [url]http://www.phpfreaks.com/forums[/url]


    luckyrye Guest

Posting Permissions

  • You may not post new threads
  • You may 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