Jump to content

Counting issue


dsbpac
Go to solution Solved by jcbones,

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
Share on other sites

  • Solution

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