msaz87 Posted February 24, 2010 Share Posted February 24, 2010 Hey all, I'm working on some code made by a different, sloppier programmer who named a column in a DB 'int' -- which I know is a mysql reserved word. To change the column would take a lot of effort in finding its references in some other pages, so I figured I would see if there is a way to SUM this column. Doing "SUM(int)" errors and while "SUM('int')" works, I can't seem to get it to then output the results like normal (IE: $row['SUM(int)'])... Any help is greatly appreciated -- thanks! Quote Link to comment https://forums.phpfreaks.com/topic/193183-how-to-sum-column-named-int/ Share on other sites More sharing options...
PravinS Posted February 24, 2010 Share Posted February 24, 2010 If SUM('int') is working the in SQL query give alias name like "SUM('int') AS cnt" and use it in $row['cnt'] Quote Link to comment https://forums.phpfreaks.com/topic/193183-how-to-sum-column-named-int/#findComment-1017279 Share on other sites More sharing options...
msaz87 Posted February 24, 2010 Author Share Posted February 24, 2010 If SUM('int') is working the in SQL query give alias name like "SUM('int') AS cnt" and use it in $row['cnt'] That doesn't seem to work... My query is as shown: $stats_query = " SELECT SUM(td_pass), SUM(int_pass), SUM(td), SUM(sacks), SUM(int_d), SUM('int') AS exp FROM XXX WHERE player_id = '$player_id' AND week = '$week'"; And the echo: <?php echo $row['exp']; ?> But instead of the SUM, it spits out all 0's... any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/193183-how-to-sum-column-named-int/#findComment-1017281 Share on other sites More sharing options...
PravinS Posted February 24, 2010 Share Posted February 24, 2010 Try like this $stats_query = " SELECT SUM(td_pass), SUM(int_pass), SUM(td), SUM(sacks), SUM(int_d), SUM(`int`) AS exp FROM XXX WHERE player_id = '$player_id' AND week = '$week'"; Quote Link to comment https://forums.phpfreaks.com/topic/193183-how-to-sum-column-named-int/#findComment-1017282 Share on other sites More sharing options...
msaz87 Posted February 24, 2010 Author Share Posted February 24, 2010 That worked, thanks PBS! Out of curiosity, what's the difference between ` and ' in this context? Quote Link to comment https://forums.phpfreaks.com/topic/193183-how-to-sum-column-named-int/#findComment-1017285 Share on other sites More sharing options...
PravinS Posted February 24, 2010 Share Posted February 24, 2010 ` is identifier quote character. If an identifier is a reserved word or contains special characters, you must quote it whenever you refer to it. ' is generally used for strings Quote Link to comment https://forums.phpfreaks.com/topic/193183-how-to-sum-column-named-int/#findComment-1017288 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.