alohatofu Posted April 28, 2007 Share Posted April 28, 2007 Hello, I have a table surv_item and a field of "name" in the name field, I would like to count the number of instances that name appear how would I go about in doing that? thanks Link to comment https://forums.phpfreaks.com/topic/49063-counting-number-of-instances/ Share on other sites More sharing options...
heckenschutze Posted April 28, 2007 Share Posted April 28, 2007 $s = "SELECT * FROM `surv_item` WHERE `name`=" . $name; //.. blah blah, get a result by running query. $instances = mysql_num_rows($result); Link to comment https://forums.phpfreaks.com/topic/49063-counting-number-of-instances/#findComment-240378 Share on other sites More sharing options...
alohatofu Posted April 28, 2007 Author Share Posted April 28, 2007 Ok, I have the following code. The problem with it is that everytime the "clli" is being dispalyed somewhere, it count as an instance. I just want the total value of instances (actual count) <div id="vvisi"><?php $right_now = time(); $start_date = $right_now - (86400*30); $clli = $objTask->clli; $query = "SELECT count(clli) FROM surv_item, surv_itemstatus " ." WHERE surv_item.itemId = surv_itemstatus.itemId AND statusDate >= FROM_UNIXTIME($start_date)" ." AND clli = '$clli'" .""; $result = mysql_query($query); $row = mysql_fetch_array($result); if ( $row[0] >= 3 ) { ?> <font color="red"><b><?php echo $GLOBALS['langForm']['chronicdetected'];?></font></b> -<?php print $row[0]; ?></a> <?php }elseif ( $row[0] < 3 ) { ?> <font color="green"><b><?php echo $GLOBALS['langForm']['nochronic'];?></font></b></a> <?php } else { } ?></div> </div> Link to comment https://forums.phpfreaks.com/topic/49063-counting-number-of-instances/#findComment-240380 Share on other sites More sharing options...
redbrad0 Posted April 28, 2007 Share Posted April 28, 2007 When you did "count(clli)" is clli actually a table name? A quick example would be to do.. select count(ID_Column) as TotalInstances from XXXX This will return one record which you can access by pulling the value of TotalInstances Link to comment https://forums.phpfreaks.com/topic/49063-counting-number-of-instances/#findComment-240516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.