doni49 Posted March 2, 2006 Share Posted March 2, 2006 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: setName1: 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] Quote Link to comment https://forums.phpfreaks.com/topic/3884-query-returns-column-name-instead-of-row-values/ Share on other sites More sharing options...
fenway Posted March 2, 2006 Share Posted March 2, 2006 You're quoting your column names, so they're being interpreted by the parser as string literals (hence the output). Drop the quotes, and you're off. Quote Link to comment https://forums.phpfreaks.com/topic/3884-query-returns-column-name-instead-of-row-values/#findComment-13464 Share on other sites More sharing options...
doni49 Posted March 2, 2006 Author Share Posted March 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/3884-query-returns-column-name-instead-of-row-values/#findComment-13466 Share on other sites More sharing options...
wickning1 Posted March 2, 2006 Share Posted March 2, 2006 For future reference:[a href=\"http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html[/a] Quote Link to comment https://forums.phpfreaks.com/topic/3884-query-returns-column-name-instead-of-row-values/#findComment-13474 Share on other sites More sharing options...
fenway Posted March 2, 2006 Share Posted March 2, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/3884-query-returns-column-name-instead-of-row-values/#findComment-13559 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.