skip to Main Content

Im working with fpdf that display two images every page, but it only display one picture every page.
Here is my code:

$id = $_GET['id'];
$stmti = $database->prepare("SELECT * FROM inv_images WHERE id = :id");
$stmti->bindParam(':id',$id);
$stmti->execute();
$imageList = $stmti->fetchAll();

foreach ($imageList as $image) { 
        $pdf->AddPage();        
        $pdf->Image('dealers_picture/'.$image['name'],30,30,160,110);

}

3

Answers


  1. I thing you are overlapping the pictures, increase the X size in second image.

    $images=['image1','image2'];
    $x=30 
    for ($i = 0; $<2 ; $i++) { 
        $pdf->AddPage();        
        $pdf->Image('dealers_picture/'.$image[$i],$x,30,160,110);
        $x+=200;
    }
    
    Login or Signup to reply.
  2. <?php
    require('fpdf.php');
    
    $pdf = new FPDF();
    $pdf->AddPage();
    //$pdf->Output();
    
    $images = '["images/er.jpg","images/dc.jpg","images/g.jpg","images/7.jpg","images/4.jpg","images/2.jpg"]';
    $imgs = json_decode($images);
    //var_dump($imgs);
    
    
    for($i=0;$i<count($imgs);$i+=1)
    {
    if(isset($imgs[$i+1])){
    
    
    if($i % 2==0){
        $pdf->Image($imgs[$i],10,12,40,30,'','');
        $pdf->Image($imgs[$i+1],60,12,40,30,'','');
        //echo $imgs[$i]." ".$imgs[$i+1];
        //echo "<hr/>";
        $pdf->AddPage();
        }
    }
    else
    {
        $pdf->Image($imgs[$i],10,12,40,30,'','');
        //echo $imgs[$i];
        //echo "<hr/>";
    }
    }
    $pdf->Output();
    ?>
    
    Login or Signup to reply.
  3. <?php
    require('fpdf.php');
    
    //Database Connection
    function con($db){
    $con=mysqli_connect($db['server'],$db['username'],$db['password'],$db['database']);
    if(!$con){echo "Check Server Connection and Database"; exit;}else{return $con;}
    }
    
    //Data Query
    function qry($con,$qryx,$suc,$err)
    {
        $qr=mysqli_query($con,$qryx);
        if(!$qr){
            return mysqli_error($con);
        }else{
            if(mysqli_num_rows($qr)>0){
            $ar=array();
            while($dbd=mysqli_fetch_array($qr))
            {$ar[]=$dbd;} return $ar;
            }else
            {return $err;}
        }
    }
    //connect the database
    $db=array("server"=>"127.0.0.1","username"=>"root","password"=>"manju!@#123","database"=>"images");
    $con = con($db);
    
    //write query to get the images in array
    $query = "select * from gallery order by id desc";
    $qry = qry($con,$query,"success","error");
    $images=array();
    if(is_array($qry))
    {
        for($i=0;$i<count($qry);$i+=1)
        {
            $images[$i]=$qry[$i]["image"];
            //echo $qry[$i]["image"]."<br/>";
        }
    }
    else
    {
        echo $qry;  
    }
    //var_dump($images);
    $imgs =$images;
    
    $pdf = new FPDF();
    $pdf->AddPage();
    //$pdf->Output();
    
    //$images = '["images/er.jpg","images/dc.jpg","images/g.jpg","images/7.jpg","images/4.jpg","images/2.jpg"]';
    //$imgs = json_decode($images);
    
    //var_dump($imgs);
    $i=0;
    
    for($i=0;$i<count($imgs);$i+=1)
    {
        if(isset($imgs[$i+1])){
        
        
        if($i % 2==0){
            $pdf->Image($imgs[$i],10,12,40,30,'','');
            $pdf->Image($imgs[$i+1],60,12,40,30,'','');
            //echo $imgs[$i]." ".$imgs[$i+1];
            //echo "<hr/>";
            $pdf->AddPage();
            }
        }
        else
        {
            $pdf->Image($imgs[$i],10,12,40,30,'','');
            //echo $imgs[$i];
            //echo "<hr/>";
        }
    }
    $pdf->Output();
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search