Get database data with Codeigniter

1

My question is how to call some DB information to the print page of a PHP system, developed in Codeigniter .

In the users DB "doctor", I have the following tables: doctor_id , name , email , password , address , phone , department_id , profile

The code below, calls the name of the doctor, as well as other information from another table, from the patient, to the print page. But, I would like to know how to include, in the same line as the doctor's name, the information of "profile" and "address"?

<?php 
$edit_data = $this->db->get_where('prescription', array('prescription_id' => $param2))->result_array(); 
foreach ($edit_data as $row): 
$patient_info = $this->db->get_where('patient' , array('patient_id' => $row['patient_id'] ))->result_array(); 
?> 
<div id="prescription_print"> 
<div><b><?php $name = $this->db->get_where('doctor' , array('doctor_id' => $row['doctor_id'] ))->row()->name; 
echo 'Drº '.$name;?> </b></div> 
<br> 
<br> 
<br> 

<?php foreach ($patient_info as $row2){ ?> 
<?php echo 'Nome do Paciente: '.$row2['name']; ?><br> 

<br> 
<br> 
<b><?php echo get_phrase('medication'); ?> :</b> 

<p><?php echo $row['medication']; ?></p> 
<br> 
<br> 
<?php } ?> 

<?php echo 'Data: '.date("d M, Y", $row['timestamp']); ?> 
<br> 

</b> 

</div> 

</div> 


<br> 

<a onClick="PrintElem('#prescription_print')" class="btn btn-primary btn-icon icon-left hidden-print"> 
Imprimir Prescrição 
<i class="entypo-doc-text"></i> 
</a> 
<?php endforeach; ?>
    
asked by anonymous 23.08.2015 / 19:10

1 answer

1

I'm not sure what the format of your bank is and what version of Laravel it uses (it looks like this is CodeIgniter as quoted by @gmsantos ).

Being CodeIgniter I believe that the solution is something like:

<div>
<?php
    $data = $this->db->get_where('doctor' , array('doctor_id' => $row['doctor_id'] ))->row();
?>
   <b><?php echo 'Drº ', $data->name;?></b><br>
   <b><?php echo 'Endereço ', $data->address;?></b><br>
   <b><?php echo 'Email ', $data->email;?></b><br>
   <b><?php echo 'Telefone ', $data->phone;?></b><br>
   <b><?php echo 'Profile ', $data->profile;?></b>
</div> 

Note that I tried to organize your code and added the phone is just an example, (using <br> is just to break the line, you can remove it).

The code looks like this, it takes the line with all data and arrow in the variable $data the object:

 $data = $this->db->get_where('doctor' , array('doctor_id' => $row['doctor_id'] ))->row();
  • Get the name $data->name
  • Get email $data->email
  • Pick up the phone% with%
  • Get profile $data->phone
23.08.2015 / 22:04