使用Set y如何使用FPDF获取该位置的记录

时间:2015-04-17 08:24:18

标签: php fpdf

Image

嗨,在下面的代码我得到上面的输出,但在那个输出我想显示在病房/房间Mini Room / 103/01,但它在si下以相同的方式显示日期和提前值。

任何人都可以帮我解决这个问题吗?

PHP

function printBodyData($header){
        global $bill_type,$dbh;
        $old_bill_type = $bill_type;
        global $res_opd,$res_adv,$res_reg,$res_ipd,$res_lab,$res_dis;
        $width = array(10,20,20,20,20,20,30,30,30);
        $this->SetLineWidth(.1);

        //printing header

        //$this->Cell(210,1,"",'T',1);
        $this->SetFont('Times','B',10);
        $this->Ln(5);
        $i=0;
        foreach($header as $column){
            $this->Cell($width[$i],9,$column,0,0,"C");  

            $i++;
        }
        $this->Ln(6);
        $this->SetFont('Times','B','10');
        $this->Cell(210,1,"",'T',1);

        //printing Body
        //echo "Billtype: ".$bill_type;
        //echo "<br> Res opd: ".$res_opd;
        $old_bill_type = $bill_type;
        $tot_opd = $tot_adv = $tot_reg = $tot_ipd = $tot_lab = 0;


        /*****************************Current In Patient STARTS***********************************/
        if($old_bill_type == "all")
            $bill_type="reg";
        if($bill_type=="reg"){
        if(count($res_opd)>0){
            $this->Ln();
            $this->SetFont('Times','B',12);
            $this->cell(50,6,"Current patient List");
            $this->Ln();
        }
        $i=1;
        foreach($res_opd as $row){  
        //$doctors = getConsultantDoctors($row['inch_doc'],$row['ipd_reg_no']);
        $doctors = array(ucwords($row['inch_doc']).", ");
        try{
            $ipd_reg_no=$row['ipd_reg_no'];
            $sql = "SELECT ab.employee_name emp_name
                    FROM address_book ab,ipd_doctor id
                    WHERE ab.employee_id = id.employee_id
                    AND id.ipd_reg_no = ipd_reg_no";

            //$sth_doc = $dbh->prepare($sql);

            $sth_doc = $dbh->query($sql);
            $all_doc = $sth_doc->fetchAll();
            foreach($all_doc as $doc){
                $doctors[] = $doc['emp_name'].", ";
            }
            $doctors = array_unique($doctors);
            //print_r($doctors);
            //$doctors = implode(" ",$doctors);
        }catch(PDOException $e){
            die($e);
        }   

            $this->SetFont('Times','',8);
            $this->cell($width[0],6,$i,0,0,'L');
            $this->cell($width[1],6,$row['reg_no'],0,0,'C');
            $this->cell($width[2],6,$row['ipd_reg_no'],0,0,'C');
            $this->cell($width[3],6,$row['first_name']." ".$row['last_name'],0,0,'L');
            $this->cell($width[4],6,getAge($row['reg_no'])."/".$row['sex'],0,0,'C');
            //$this->cell($width[5],6,ucwords($row['inch_doc']),0,0,'L');
            $i=1;
            foreach($doctors as $d){
            if(($i)>0)
            $this->SetX(110);
            $this->cell($width[5],6,$d,0,0,'L');
            if(($i)>0)
            $this->Ln();
            $i++;

            }



            $this->cell($width[6],6,$row['room_category_name']."/".$row['room_id']."/".$row['floor_no'],0,0,'L');




            //$this->cell($width[6],6,$row['room_category_name']."/".$row['room_id']."/".$row['floor_no'],0,0,'C');
            $this->cell($width[7],6,getOutputDate($row['admit_date'])."/".$row['time'],0,0,'C');

            $this->cell($width[8],6,$row['advance'],0,0,'C');
            $this->Ln();
            $i++;

        }

1 个答案:

答案 0 :(得分:0)

萨拉姆。您的代码存在一些关键问题,所有问题都应该解决。

让我们从Cell方法开始。首先,您应该使用大写Cell而不是C来编写cell。在您的代码中,您试图将每位医生打印到同一位置,如下所示:

foreach($doctors as $d){
    if(($i)>0)
        $this->SetX(110);
    $this->cell($width[5],6,$d,0,0,'L');
    if(($i)>0)
        $this->Ln();
    $i++;
}

这会弄乱您对Cell的后续调用,因此我强烈考虑将您的代码修改为此问题。此外,您可能没有分配足够的单元格空间来打印您的某些信息。有些医生有很长的名字,比如Dr. Shakeel Jeelani。如果要打印名称的宽度大于单元格的宽度,您将开始看到一些不需要的行为。也可能是1 Year/female上的信息大于单元格,因为文本非常接近Consultant的单元格。看看并确保您的数字加起来,并且您的字段的宽度不超过单元格的宽度。 FPDF有一个名为GetStringWidth的函数。