Jump to content

Counting issue


dsbpac

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/281099-counting-issue/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/281099-counting-issue/#findComment-1444657
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.