Jump to content

Query returns column name instead of row values


doni49

Recommended Posts

This is a code snippet from my PHP file.
[code]
        $query = "SELECT 'setName', 'fields' FROM userFieldSets WHERE user_id='$uid'";
        $result = @mysql_query ($query) or die ('I cannot get fields from the database because: ' . mysql_error());
        $row = mysql_fetch_array ($result, MYSQL_NUM);

        if ($row) { // A match was made.
            echo "0:  " . $row[0] . "<br>";
            echo "1:  " . $row[1] . "<br>";
        }        
[/code]

It shows this in my browser.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
0: setName
1: fields
[/quote]

This is copy/pasted from phpMyAdmin.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
[b]id user_id tblName setName fields
[/b]1 1 mainIndex Default 1,2,3,4,5,6,7,8,10,13,14
2 1 propertyAmtsDue Default 1,2,3,4,5,6,7,8,10,13,14
3 1 propertyContact Default 1,2,3,4,5,6

[/quote]

Link to comment
Share on other sites

That's strange. I only put them in there because I was getting error messages that there was something wrong with the syntax.

When I put them in the error message went away.

Is "Fields" a reserved name or something?

While waiting to hear from someone, I kept trying different things. I changed "Fields" to "Flds" and still got the column names anyway. But then as soon as I took the quotes back out, it worked fine (with it still using "Flds").

Thanks for the help.
Link to comment
Share on other sites

Yes, FIELDS is reserved -- the "correct" way to request such columns is with backticks (e.g. `fields`); however, the best practice is to simply avoid using these to begin with. wickning1 give you a link to a list of these.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.