tigomark Posted September 11, 2007 Share Posted September 11, 2007 Hello, I am having problems getting a proper row count. Here is my Code. function getZoneQuery(){ $this->sql = sprintf("SELECT insp_config.label AS inspType, asset.fleet AS assetName, zone_status.inspid AS inspID, TO_CHAR(zone_status.insp_date, 'HH:MM:SS'), zone.name FROM zone_status JOIN inspection_record ON (inspection_record.id = zone_status.inspid) JOIN insp_config ON (insp_config.id = inspection_record.cfgid) JOIN asset ON (asset.id = zone_status.assetid) JOIN zone on (zone.id = zone_status.zoneid) " ); } function countAll(){ $this->sql = sprintf(" SELECT COUNT(pkey) FROM zone_status JOIN zone ON (zone_status.zoneid = zone.id) JOIN inspection_record ON (inspection_record.id = zone_status.inspid) JOIN insp_config ON (insp_config.id = inspection_record.cfgid) JOIN asset ON (asset.id = zone_status.assetid)"); } Then I try to join up the first collum of the dbase with all other collums that include the same inspection. function numResults(){ return(count($this->result)); } function runQuery(){ $this->countAll(); $this->executeSQL(); $this->total_count = pg_result($this->result, 0, 0); $this->getZoneQuery(); $this->executeSQL(); $inspID = 0; for($i=0;$i< pg_numrows($this->result);$i++){ if ($inspID != pg_result($this->result, $i, 2)){ $inspID = pg_result($this->result, $i, 2); if ($inspID != 0){ //echo "<pre>"; print_r ($data); echo "</pre>"; $entry = new ZoneTypeEntry($data); $this->data[] = $entry; $j = 1; $data = array(); } $data['inspType'] = pg_result($this->result, $i, 0); $data['assetName'] = pg_result($this->result, $i, 1); $data['inspID'] = pg_result($this->result, $i, 2); } $data["timestamp$j"] = pg_result($this->result, $i, 3); $data["zonename$j"] = pg_result($this->result, $i, 4); $j++; } pg_free_result($this->result); return(true); } } Now I am not getting the right counts because I am trying to get the count from the wrong sql statement. I am trying to figure out a way to get a count from the second results to get a proper row count. Quote Link to comment https://forums.phpfreaks.com/topic/68854-solved-problems-getting-table-counts/ Share on other sites More sharing options...
btherl Posted September 12, 2007 Share Posted September 12, 2007 Why do you need to use pg_num_rows() on the first query when you have already fetched the total count in the second query? Is it pg_num_rows() that you are having trouble with? Quote Link to comment https://forums.phpfreaks.com/topic/68854-solved-problems-getting-table-counts/#findComment-346511 Share on other sites More sharing options...
tigomark Posted September 13, 2007 Author Share Posted September 13, 2007 Fixed Thanks Quote Link to comment https://forums.phpfreaks.com/topic/68854-solved-problems-getting-table-counts/#findComment-347892 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.