Jump to content

Recommended Posts

Hello,

 

I'm a bit over my head today and need some help.

I have info that I am pulling from multiple databases and then joining into an array to make the data appear as a single row.



//data query

function getZoneQuery(){
$this->sql = sprintf("SELECT insp_config.label AS inspType, asset.fleet AS assetName, zone_status.inspid AS inspID, operator.fname || ',' || operator.lname As operator,
				 TO_CHAR(zone_status.insp_date, 'DD Mon YYYY') AS date, 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 operator ON (operator.id = inspection_record.operatorid) 
				 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)
				 " );
$this->addAllConstraints();
$this->addSorts();	

  //printf("SQL: %s <br>", $this->sql);
    
  }

//count query

function countAll(){
$this->sql = sprintf("SELECT COUNT(*) FROM inspection_record 
JOIN insp_config ON (insp_config.id = inspection_record.cfgid)");
$this->addAllConstraints();
  function runQuery(){
    $this->countAll();
    $this->executeSQL();
    $this->total_count = pg_result($this->result, 0, 0);

    $this->getZoneQuery();
    $this->executeSQL();




    $inspID = pg_result($this->result, $i, 2);
    $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['operator'] = pg_result($this->result, $i, 3);
    $data['date'] = pg_result($this->result, $i, 4);
    $j =1;

    for($i=0;$i< pg_numrows($this->result);$i++){

      if ($inspID != pg_result($this->result, $i, 2)){
        $this->data[] = new ZoneTypeEntry($data);
//        echo "<pre>$i"; print_r(current($this->data)); echo "</pre>";

        $j = 1;
      

        $inspID = pg_result($this->result, $i, 2);
    $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['operator'] = pg_result($this->result, $i, 3);
        $data['date'] = pg_result($this->result, $i, 4);
      }
  	
      $data["timestamp$j"] = pg_result($this->result, $i, 5);
      $data["zonename$j"] = pg_result($this->result, $i, 6);
  
      $j++; 
    }
//    echo "<pre>"; print_r(current($this->data)); echo "</pre>";

    $this->data[] = new ZoneTypeEntry($data);
    pg_free_result($this->result);
    return(true);
  }
}

 

Now since I am creating custom rows I can't use sql to actually set row limits per page so I need to write a custom script to only show 20 rows of data per page until the rows end.

 

Currently I have a varibles set and I am trying to finish it off

 

function rowCountLabel(){
  if($this->result_count == 0){
    return(NO_RECORDS_FOUND_LABEL);
  }
  return(sprintf(ROW_COUNT_LABEL,
                  ($this->startrow + 1),
                  ($this->startrow + $this->count),
                  $this->result_count));
                  
}

$this->offset = 20;
$this->count = 20;


 

This gives the row counts and total counts . I also have the offset and count limit but I'm not sure from where to go from here to limit by page.

 

any help would be great

Link to comment
https://forums.phpfreaks.com/topic/69619-making-php-auto-increment-table-rows/
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.