0

I'm re-posting my question so that it'll gain more audience. Seems like the others doesn't see it since I posted it last week.

I'm displaying a data outside and inside the table. When I tried to call the data on inside the table, it works perfectly fine but whenever I call it outside, it suddenly doesn't show. This part right here...

$pdf->MultiCell(194,4,"STORM SURGE INFORMATION",0,'C', false);
$pdf->Cell(191,4,"STORM SURGE: WARNING # ",0,0,'C');
$pdf->Cell(-136,4,$fetch['warning'],0,1,'C');

$pdf->Cell(172,4,"FOR: TYPHOON ",0,0,'C');
$pdf->Cell(-119,4,$fetch['typhoon'],0,1,'C');

$pdf->Cell(175,4,"ISSUED AT ",0,0,'C');
$pdf->Cell(-135,4,$fetch['date'],0,1,'C');

My PDF currently look like this.

enter image description here

Can somebody help me figure out what is wrong or missing with my codes?

<?php

require("con.php");

$sql="SELECT * FROM table ORDER BY ssh REGEXP '^[^A-Za-z0-9]' ASC, ssh DESC";

$records=mysql_query($sql);
$fetch = $records[0];

require("library/fpdf.php");

class PDF extends FPDF{
  function Header(){
  }
  function Footer(){
  }
}

$pdf = new PDF('p', 'mm', 'Legal');
$title = 'Storm Surge Warning';
$pdf->SetTitle($title);
$pdf->AliasNbPages('{pages}');
$pdf->SetAutoPageBreak(true,40);

$pdf->AddPage();
$pdf->Ln();

$pdf->SetFont('Arial', 'B', 10);

$pdf->MultiCell(194,4,"STORM SURGE INFORMATION",0,'C', false);
$pdf->Cell(191,4,"STORM SURGE: WARNING # ",0,0,'C');
$pdf->Cell(-136,4,$fetch['warning'],0,1,'C');

$pdf->Cell(172,4,"FOR: TYPHOON ",0,0,'C');
$pdf->Cell(-119,4,$fetch['typhoon'],0,1,'C');

$pdf->Cell(175,4,"ISSUED AT ",0,0,'C');
$pdf->Cell(-135,4,$fetch['date'],0,1,'C');

$pdf->Ln(1);

$pdf->SetBorders(array('LT', 'LT', 'LT', 'LT', 'TLR'));
$pdf->SetWidths(array(25, 27, 35, 54, 53));
$pdf->SetAligns(array('C', 'C', 'C', 'L', 'L'));

$pdf->SetFont('Arial', 'B', 10);

$pdf->Row(array("SS Height",
            "Provinces",
            "Low Lying Coastal Areas in the Municipalities of:",
            "IMPACTS",
            "ADVICE/Actions to Take"), 1);

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


while($row = mysql_fetch_array($records)){
  $pdf->Row(array($row['ssh'],
  $row['provi'],
  $row['muni'],
  $row['impact'],
  $row['advice']), 1);
  }

$pdf->SetBorders(array('T', 'T', 'T', 'T', 'T'));
$pdf->Row(array('','','','',''), 1, false, 1);

$pdf->OutPut();
?>
desteen
  • 187
  • 1
  • 1
  • 10
  • You need to solve your basic issue which is retrieving values from your database (`$fetch` variable in this case). As discussed in your previous question if you `print_r($records);` right after your query what does it show? What are the results if you run that query in PHPmyAdmin or similar tool? – Dave Mar 27 '19 at 16:05
  • @Dave it displays the data that i am calling. – desteen Apr 01 '19 at 03:09

1 Answers1

1

You are trying to use negative X-Position value. I hope, that's why it's not working.

do you want something like below:

Example

Use Limit to take Latest Record

$sql="SELECT * FROM twothree ORDER BY ssh REGEXP '^[^A-Za-z0-9]' ASC, ssh DESC LIMIT 1";
//echo $sql;
$records=mysql_query($sql);
if (mysql_num_rows($records)) {
 $fetch = mysql_fetch_assoc($records);
}

$pdf->Ln(10);
$pdf->Cell(194, 4,"STORM SURGE: WARNING # " . $fetch['warning'], 0,0,'C');
$pdf->Ln();
$pdf->Cell(194, 4,"FOR: TYPHOON " . $fetch['typhoon'],0,0,'C');
$pdf->Ln();
$pdf->Cell(194,4,"ISSUED AT " . $fetch['date'],0,0,'C');
$pdf->Ln();

$pdf->Ln(20);

Example

$pdf->Cell(60, 4,"", 0,0,'C');
$pdf->Cell(60, 4,"STORM SURGE: WARNING # :", 0,0,'L');
$pdf->setX(125);    
$pdf->Cell(60, 4,$fetch['warning'], 0,0,'L');
$pdf->Ln();
$pdf->Cell(60, 4,"", 0,0,'C');
$pdf->Cell(60, 4,"FOR: TYPHOON :", 0,0,'L');
$pdf->setX(100);    
$pdf->Cell(60, 4,$fetch['typhoon'], 0,0,'L');
$pdf->Ln();
$pdf->Cell(60, 4,"", 0,0,'C');
$pdf->Cell(60, 4,"ISSUED AT : ", 0,0,'L');
$pdf->setX(100);    
$pdf->Cell(60, 4,$fetch['date'], 0,0,'L');
$pdf->Ln();

Main Query

$sql="SELECT * FROM twothree ORDER BY ssh REGEXP '^[^A-Za-z0-9]' ASC, ssh DESC";
//echo $sql;
$records=mysql_query($sql);
rsmdh
  • 128
  • 1
  • 2
  • 12
  • Seems like I got a problem with the `$fetch['warning']` `$fetch['typhoon']` `$fetch['date']`. It still doesn't display. @rsm – desteen Mar 26 '19 at 23:27
  • @desteen, are you getting data in $fetch array? – rsmdh Mar 27 '19 at 11:36
  • I'm sorry I think you misunderstood. What I mean is that, it is working on the `while($row = mysql_fetch_array($records))` part but not on the `$fetch['warning'] $fetch['typhoon'] $fetch['date']`. It still doesn't display. @rsm – desteen Mar 28 '19 at 05:32
  • @desteen, could you please give sample output $fetch = $records[0] – rsmdh Mar 28 '19 at 05:35
  • I am actually using `$fetch = mysql_fetch_array($records);` to fetch data from the db and display in in pdf. I thought it works perfectly fine since even the `$fetch['warning'] $fetch['typhoon'] $fetch['date']` are displaying. However I noticed some issue where the first row on the table isn't displaying and I fixed that by changing the code into `$fetch = $records[0];`. That's when I got this problem. The table is displaying everything now but the `$fetch['warning'] $fetch['typhoon'] $fetch['date']` isn't. @rsm – desteen Mar 28 '19 at 06:21
  • @desteen, i want to know what is the value is coming $fetch. so echo "
    "; print_r($fetch);echo "
    ". send me output.
    – rsmdh Mar 28 '19 at 07:07
  • I'm not sure where to put it but I putted it under the `$fetch = $records[0];` and when I run it, it says **Resource id #4** followed by a Fatal Error. @rsm – desteen Mar 28 '19 at 23:14
  • try to add exit after this line echo "" then check it – rsmdh Mar 29 '19 at 04:49
  • It removed the _Fatal Error_ and displayed `Resource id #4` @rsm – desteen Mar 29 '19 at 04:58
  • Please refer below links/ search on google: [link]https://stackoverflow.com/questions/13189764/resource-id-4-why-am-i-getting-this [link]https://stackoverflow.com/questions/30586471/php-resource-id-4 **Your query result is a resource. You need to extract the results/data from it.** – rsmdh Mar 29 '19 at 05:10
  • It's printing something from the array now. And then what should I do next? Whenever I remove `var_dump($fetch);` it goes back to the pdf but when I put it there it just displayed the data but not on pdf. @rsm – desteen Mar 29 '19 at 05:26
  • You can write on query to fetch only 1 record and limit. can you please try below and check. $sql="SELECT * FROM table ORDER BY ssh REGEXP '^[^A-Za-z0-9]' ASC, ssh DESC LIMIT 1"; $result=mysql_query($sql); if (mysql_num_rows($result)) { $fetch = mysql_fetch_assoc($result); } – rsmdh Mar 29 '19 at 06:29
  • The thing is, I am using `$sql="SELECT * FROM table ORDER BY ssh REGEXP '^[^A-Za-z0-9]' ASC, ssh DESC";` to fetch all data and display it outside and inside the table. The datas on the table are inside an array like this `$pdf->Row(array($row['provi'], $row['muni'], $row['impact'], $row['advice']), 1);` and inside the while loop which is this `while($row = mysql_fetch_assoc($records)){` while the outside data are being called like this `$fetch['date']`. I don't really understand your recent reply. @rsm – desteen Mar 29 '19 at 06:51
  • @desteen, actually, you are fetching all the values from a table then you are taking the first value from that array.I think you are getting an this here. try like as per my last reply. i told to you write an another query to take only value to use LIMIT then check it. how is it coming.? – rsmdh Mar 30 '19 at 13:03
  • So I tried what you said and this is how my code looks like now https://pastebin.com/eq870TRF and when I run it it displays the first data from the `db` but not on pdf format. @rsm – desteen Apr 01 '19 at 00:24
  • @desteen, could you please show output of var_dump($fetch);. I want to check what is the value is coming. – rsmdh Apr 01 '19 at 06:19
  • Something like this `array(9) { ["id"]=> string(2) "65" ["ssh"]=> string(9) "2-3Meters" ["provi"]=> string(8) "La Union" ["muni"]=> string(110) "Bangar, Luna, Balaon, Bacnotan, San Juan, San Fernando City, Bauang, Caba, Aringay, Agoo, Santo Tomas, Rosario" ["impact"]=> string(201) "- Severe damage to communities, coastal/ marine infrastructures and disruptions to all marine-related activities. - Significant erosion to beaches. - Possible River flooding due to storm surge." ["date"]=> string(10) "2019-03-19" ["typhoon"]=> string(13) "Rosita (YUTU)" ["warning"]=> string(2) "01" }` @rsm – desteen Apr 01 '19 at 06:22
  • So I just noticed that the 2nd row from the database is displaying. The first ID on my db is `64` but what displaying is `65` @rsm – desteen Apr 01 '19 at 06:30
  • 1
    i checked ur code. it's working fine for me. please how a look this code https://pastebin.com/UyDCAtR0 – rsmdh Apr 01 '19 at 06:34
  • Yup! It works on mine now. Can you edit your answer on the top please so that I can accept your answer and wont confuse the others. Thank you so much! – desteen Apr 01 '19 at 06:39