Guys,I have my table data ,I want to retrieve them to pdf file using php,The problem is,when I use 'where condition' in a select statement, I do not receive any data,but when I do not use ,I get data from one row from the database table.Any help please!!

 <?php session_start();
require('fpdf.php');
$d=date('d_m_Y');

class PDF extends FPDF
{

function Header()
{
    //Logo
$name="";
    $this->SetFont('Times','','17');
    //Move to the right
    $this->Cell(80);
    //Title
    $this->Cell(1,65,"RFO");
$this->Cell(20,70,"",0,0,'C');
$this->SetFont('Times','B','11');
$this->Cell(-174,75,"DATE:".date('d-m-Y'),0,0,'C');
$this->Cell(170,93,"LINK DETAILS",0,0,'C');
$this->SetFont('Times','','9');
$this->Cell(-183,110,"LINK:",0,0,'C');
$this->Cell(183,127,"AREA:",0,0,'C');
$this->SetFont('Times','B','11');
$this->Cell(-150,150,"TIMELINE OUTAGE:",0,0,'C');
$this->SetFont('Times','','9');
$this->Cell(150,167,"TIME LINK WENT DOWN:",0,0,'C');
$this->Cell(-135,184,"TIME REPORTED BY CUSTOMER:",0,0,'C');
$this->Cell(135,200,"TIME TEAM REPORTED TO SITE:",0,0,'C');
$this->Cell(-142,218,"TIME LOCATED THE FAULT:",0,0,'C');
$this->Cell(142,235,"TIME LINK CAME BACK UP:",0,0,'C');
$this->SetFont('Times','B','11');
$this->Cell(-135,262,"ROOT CAUSE OF FAILURE:",0,0,'C');
$this->SetFont('Times','','9');
$this->Cell(95,279,"CAUSE:",0,0,'C');
$this->Cell(-83,296,"DESCRIPTION:",0,0,'C');
$this->Cell(125,320,"ACTION TAKEN FOR RESTORATION:",0,0,'C');
$this->Cell(-145,360,"PREVENTIVE MEASURES:",0,0,'C');
    //Line break
    $this->Ln(-342.5);
}

//Page footer
function Footer()
{

}

//Load data
function LoadData($file)
{
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}

//Simple table
function BasicTable($header,$data)
{ 

$this->SetFillColor(255,0,0);
$this->SetDrawColor(128,0,0);
$this->SetFont('Times','',8);
$w=array(30,15,20,10,10,10,10,10,15,15,15,15,15);

//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
//Data
foreach ($data as $eachResult) 
{ //width
$this->Cell(10);
$this->Cell(80,6,$eachResult["link"],1);//hapa natakiwa niweke 1,hiyo 0 nimeweka kw mda tu
$this->Ln(8.5);
$this->Cell(11);
$this->Cell(80,6,$eachResult["area"],1);//hapa natakiwa niweke 1,hiyo 0 nimeweka kw mda tu
$this->Ln(20);
$this->Cell(42.5);
$this->Cell(20,6,$eachResult["tlwd"],1);
$this->Cell(20,6,$eachResult["dlwd"],1);
$this->Ln(8.5);
$this->Cell(57.5);
$this->Cell(20,6,$eachResult["trbc"],1);
$this->Cell(20,6,$eachResult["drbc"],1);
$this->Ln(8);
$this->Cell(57.5);
$this->Cell(20,6,$eachResult["ttrts"],1);
$this->Cell(20,6,$eachResult["dtrts"],1);
$this->Ln(9);
$this->Cell(50);
$this->Cell(20,6,$eachResult["tlf"],1);
$this->Cell(20,6,$eachResult["dlf"],1);
$this->Ln(8.5);
$this->Cell(50);
$this->Cell(20,6,$eachResult["tlcb"],1);
$this->Cell(20,6,$eachResult["dlcb"],1);
$this->Ln(21.9);
$this->Cell(17);
$this->Cell(80,6,$eachResult["rcause1"],1);
$this->Ln(8.5);
$this->Cell(28);
$this->Cell(80,6,$eachResult["dfailure1"],1);
$this->Ln(12);
$this->Cell(68.5);
$this->Cell(80,6,$eachResult["actaken1"],1);
$this->Ln(20);
$this->Cell(49);
$this->Cell(80,6,$eachResult["pmeasure1"],1);
$this->Ln();
}
}

//Better table
}
$r2=$_GET['r']; 
$pdf=new PDF();
$header=array();

//Data loading
//*** Load MySQL Data ***//
include("connect.php");

$strSQL = "SELECT * FROM rfos"; //(this retrieve only first row)

//$strSQL = "SELECT * FROM rfos where r='$r2'";//(this does not retrieve anything)

$objQuery = $con->query($strSQL);
$objQuery->fetch_assoc();
$resultData = array();
for($i=0;$i<$objQuery->num_rows;$i++){//ila hapa inatakiwa iwe 0 sio moja,moja nimeweka kwa mda tu
$result = $objQuery->fetch_array(MYSQLI_ASSOC);
$result = mysqli_fetch_array($objQuery);
array_push($resultData,$result);
//print_r($resultData);
}

//-------------------------
/*  $sql=$strSQL;
  if(!$results=$con->query($sql)){
  die('There was an error running the query['.$con->error.']');
  }
  while($row=$results->fetch_assoc()){
  echo '<br>'.$row['link'];
  }*/
//************************//
 function forme()

{
$d=date('d_m_Y');
//header("location:rfoview.php");

//$_SESSION['d']=.$d.".pdf";
//echo "<a href=".$d.".pdf>DOWNLOAD</a>";
}

$pdf->SetFont('Arial','',6);

//*** Table 1 ***//
$pdf->AddPage();
$pdf->Image('mylogo.jpg',10,4,100);
$pdf->Ln(35);
$pdf->BasicTable($header,$resultData);
forme();
$pdf->Output("$d.pdf","F");

header('Location:'.$d.'.pdf');
?> 
Member Avatar for diafol

Instead of dressing this thread up with PDF stuff, why not break down the issue to what you assume the problem is - namely mysqli not returning data when you have a WHERE clause.

Not until way past line 100 do you start the important stuff:

$r2=$_GET['r']; 
$pdf=new PDF();
$header=array();
//Data loading
//*** Load MySQL Data ***//
include("connect.php");
$strSQL = "SELECT * FROM rfos"; //(this retrieve only first row)
//$strSQL = "SELECT * FROM rfos where r='$r2'";//(this does not retrieve anything)

This is very dangerous as you allow the user to inject SQL directly into your statement. You must use escaping functions or better still use prepared statements.

Error trapping / checking the query will help you with this too. We are assuming you actually have a field named 'r' and that there is always a querystring parameter named 'r'. If not you will get an error stating that the index does not exist. You should always have a conditional to apply a filter (WHERE) and bind any values if using prepared statement ...

if(isset($_GET['r'])){
//...
}else{
//...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.