Retrieve database data with Codeigniter

Asked

Viewed 1,133 times

2

My question is how to call some DB information to the printing 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 doctor’s name, as well as other information from another table, the patient, to the printing page. But, I would like to know how to include, in the same line as the doctor’s name, the information "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; ?>
  • We are a community of Portuguese language (European and Brazilian), there is no need to use English (and it is not recommended), because everyone here speaks mostly only Portuguese. -- I changed the title because the problem seems to be in downloading the data and not in printing.

  • 1

    Laravel or Codeigniter?

  • Correction! You are in Codeigniter, you are absolutely right! I apologize for the mistakes and thank you for your help. Namaste!

1 answer

1


I’m not sure what the format of your bank and what version of Laravel you use (it looks like it’s about Codeigniter as quoted by @gmsantos).

Being Codeigniter I believe 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, (the use of <br> It’s just to break the line, you can remove).

The code looks like this, it takes the line with all the 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 the e-mail $data->email
  • Pick up the phone $data->phone
  • Get the profile $data->profile
  • 1

    It worked perfectly! Awesome! I am grateful for your guidance. Namaste!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.