Jump to content

[SOLVED] Problems Getting Table Counts


Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/68854-solved-problems-getting-table-counts/
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.