dsbpac Posted August 12, 2013 Share Posted August 12, 2013 I'm having an issue counting a table with table columns listed as numbers. I have a table called timetable with fields 1, 2, 3, 4 so on. If I try to count like this <?php $query = "SELECT 96, COUNT(96) FROM timetable WHERE 96='blah'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo " (". $row['COUNT(96)'] .")"; } ?> It will return the value as zero. If i change the columns from 96 to name like <?php $query = "SELECT name, COUNT(96) FROM timetable WHERE name='blah'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo " (". $row['COUNT(96)'] .")"; } ?> It will return the correct value?? Thank you for any help Quote Link to comment Share on other sites More sharing options...
kicken Posted August 12, 2013 Share Posted August 12, 2013 If you have a column literally named '96', you are doing something horribly wrong. In your queries 96 is going to be treated as a numeric value, not a column name. 96='blah' is false and would match no rows. Quote Link to comment Share on other sites More sharing options...
dsbpac Posted August 12, 2013 Author Share Posted August 12, 2013 There is not some type or work around that I can do in order for it to ready these as values? Quote Link to comment Share on other sites More sharing options...
Solution jcbones Posted August 12, 2013 Solution Share Posted August 12, 2013 There is, but the greater question is in your database design. If you have 96 columns in your table, then I suggest that your database isn't normalized. http://http://www.youtube.com/watch?v=BGMwuOtRfqU&list=PL196FE5448948D9B4 <-data logic modeling (9 vids, must watch). The work around is to use backticks (`) around the column name. Quote Link to comment 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.