Search code examples
mysqlcodeigniterdompdf

PDF did not show name instead of id in Codeigniter


I have a project to show a certificate based on id where i click. That table contains name, id. But whenever I click, it shows id not name from id.

$nama = $this->db->query("SELECT nama FROM m_siswa where id = '$uri4' ")->result_array();
            /* $where = array('id' => $id);
            $person_info = $this->m_siswa->get($where);  */
            $viewData['id'] = $uri4;
            $this->load->view('v_sertifikat',$viewData);
            exit;

When I change $uri4 to $nama, it won't work. Note $uri4 is based on ID where I click

$uri4 is id_siswa from table siswa, marked as 9720

But when I Click "cetak sertifikat (or print certificate) to pdf," it displays id not name from $uri4

this is the output, but it did not show name

this is certificate view.

<div style=\"width:800px; height:600px; padding:20px; text-align:center;  #787878; margin-left: auto; margin-right: auto; \">

        <div  class='container-fluid' style=\"width:750px; height:550px; padding:20px; text-align:center;  #787878; margin: auto;  background-size: cover;\" >

            <span id='id1' style=\"font-size:30px; margin-top: -85px; \" ><img src=\"res/arkaplan6.jpeg\" alt=\"İKÜ LOGO\" height=\"795px\" width=\"1200px\"></span>

            <br><br>
             <br><br>
            <span style=\"font-size:50px; font-weight:bold\">SERTIFIKAT</span>
            <br><br>
            <br><br>
            <span style=\"font-size:30px\" ><b>$nama</b></span><br/><br/>
            <span style=\"font-size:25px\"><i>atas keberhasilannya telah mencapai nilai yang fantastis</i></span> <br/><br/>

            <span style=\"font-size:25px;\"><i>Anda telah lulus untuk sertifikat ini</i></span><br>
            <span style=\"font-size:10px\" ><b>id : $id</b></span><br/><br/>

             <br><br><br><br> <br> 

        </div>

Note $nama is used to show the name from id, not the id number. Can you help to solving this?


Solution

  • In $name you get the result of you query as array

    so if you want pass the content of the result you should

        $result = $this->db->query("SELECT nama FROM m_siswa where id = '$uri4' ")->result_array()
    
    
       $viewData['id'] = $uri4;
       $viewData['name'] = $result[0]['nama'];