FPDF does not scroll through all the selectable records - php

I am working on an attendance sheet module. What I am suppose to do is that write a simple select query which will select worker name and staff id from the table and output it using fpdf in a sheet in portrait orientation.
My code is:
<?php
$date = 'Month: '.date("M-Y");
$sr=1;
//$empname = '$_GET["selectuser"]';
$f=0.75*10;
require('fpdf.php');
/*------------------------- header columns ---------------------------------*/
$conn = new mysqli('localhost', 'tahir', 'abcdef', '12345');
if($conn->connect_error){
die("Error in DB connection: ".$conn->connect_errno." : ".$conn->connect_error);
}
$select = "SELECT * FROM tbl_th";
$result = $conn->query($select);
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',14);
while($row = $result->fetch_object()){
$empname = $row->emp_name;
$memberid = $row->member_id;
$trade = $row->trade;
// $pdf=new FPDF();
// $pdf->AddPage(); $pdf->SetFont('Arial','B',$f);
$pdf->SetX(5);
$pdf->SetY(15);
$pdf->MultiCell(194,10,"Attendance Sheet",1,'C', false);
$pdf->SetX(5);
$pdf->SetY(25);
$pdf->Cell(194,10,$date,1,1,'C',false);
$pdf->SetX(5);
$pdf->SetY(35);
$pdf->Cell(15,10,"Sr.No.",1,'C', true);
$pdf->SetX(5);
$pdf->SetY(35);
$pdf->MultiCell(90,10,"Worker Name",1,'C', false);
$pdf->SetX(5);
$pdf->SetY(35);
$pdf->MultiCell(115,10,"Staff ID",1,'R', false);
$pdf->SetX(5);
$pdf->SetY(35);
$pdf->MultiCell(145,10,"Trade",1,'R', false);
$pdf->SetX(5);
$pdf->SetY(35);
$pdf->MultiCell(194,10,"Signature",1,'R', false);
/*------------------------- columns start ---------------------------------*/
$pdf->SetX(5);
$pdf->SetY(45);
$pdf->Cell(15,10,$sr++,1,'C', true);
$pdf->SetX(5);
$pdf->SetY(45);
$pdf->MultiCell(90,10,$empname,1,'C', false);
$pdf->SetX(5);
$pdf->SetY(45);
$pdf->MultiCell(115,10,$memberid,1,'R', false);
$pdf->SetX(5);
$pdf->SetY(45);
$pdf->MultiCell(145,10,$trade,1,'R', false);
$pdf->SetX(5);
$pdf->SetY(45);
$pdf->MultiCell(194,10,"",1,'R', false);
$pdf->Output();
}
?>
PDF Output
I was expecting it to display all the records of the table. But it is only displaying the first record of the table.
I can't get it to scroll through all the records. I'm done. I can't. I wanna keep using fpdf. I don't wanna switch to other options.
Please help me what is that I am missing in this script of mine? Please thanks in advance!

Related

How to make download popup work in chrome when download data from api?

I Successfully download data from the API to excel but there's no download confirmation in chrome. It's just save it in the vendor problem. I want to make shown in Downloads of chrome
public function download()
{
$host ="https://jsonplaceholder.typicode.com/posts";
$process = curl_init($host);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Id');
$sheet->setCellValue('B1', 'Name');
$sheet->setCellValue('C1', 'Skills');
$sheet->setCellValue('D1', 'Address');
$rows = 2;
$results=json_decode($return);
foreach ($results as $val){
$sheet->setCellValue('A' . $rows, $val->id);
$sheet->setCellValue('B' . $rows, $val->userId);
$sheet->setCellValue('C' . $rows, $val->title);
$sheet->setCellValue('D' . $rows, $val->body);
$rows++;
}
$writer=new Xlsx($spreadsheet);
$writer->save('json.xlsx');
}
Its not done by PHP Code your need is Browser functionality
check this link to make Chrome to show downloads How to make chrome downloads to display

cURL fast way to stream images

I know that cURL's performance is quite fast however since the files I'm streaming is on a different server, it took 4-5 minutes to complete.
Is there any way to do 100 requests in 10-15 seconds? I have tried multi-process of cURL and the effect is still the same even file_get_contents().
Thank you
<?php
require_once('FileMaker.php');
use \setasign\Fpdi;
use \setasign\Fpdi\PdfParser\StreamReader;
require_once('FPDi/vendor/setasign/fpdf/fpdf.php');
require_once('FPDi/vendor/autoload.php');
require_once('FPDi/src/PdfParser/StreamReader.php');
$pdf = new Fpdi\Fpdi();
$fm = new FileMaker('database sample', 'location sample', 'username sample',
'password sample');
$connected = $fm->getLayout('Accessioning | Desktop | Form');
if (FileMaker::isError($connected)) :
// echo '<script> alert("NOT CONNECTED"); </script>';
endif;
//echo '<script> alert("CONNECTED"); </script>';
$record_gathered = $fm->getRecordByID("Accessioning | Desktop | Form", "18226");
$related_records = $record_gathered->getRelatedSet('Library | Accession Catalog Items');
$result_gathered_information = array();
$result = array();
if (!FileMaker::iserror ($related_records)) {
foreach($related_records as $related_record){
#$counter = $counter + 1;
if ($counter <= 3){
$fetchURL = 'http://sampleURL/SuperContainer/RawData/Library/Catalog/Items/'. $related_record->getField('Library | Accession Catalog Items::recno') . '/?a=1';
$result_gathered_information[] = $fetchURL;
}
}
}
foreach ($result_gathered_information as $detectedinfo){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $detectedinfo);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result[] = curl_exec($ch);
curl_close($ch);
}
foreach ($result as $file) {
$pageCount = $pdf->setSourceFile(StreamReader::createByString($file));
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// add a page with the same orientation and size
$pdf->AddPage($size['orientation'], $size);
// use the imported page
$pdf->useTemplate($templateId);
$pdf->SetFont('Helvetica');
$pdf->SetXY(5, 5);
}
}
$pdf->Output();

how to post data to another file in php

need a help in this regard
1. I need to design a user input form which has three text fields say T1, T2, T3.
2. Now the inpust from these three should be packed into encode_json
3.I have a table with multiple rows, with auto increment id 1,2,3,4 so on. Now the same encoded json message should be passed onto a file send_message.php along with id and encoded json message.
here is the send_message.php
<?php
if (isset($_GET["regId"]) && isset($_GET["message"])) {
$regId = $_GET["regId"];
$message = $_GET["message"];
include_once './GCM.php';
$gcm = new GCM();
$registatoin_ids = array($regId);
$message = array("price" => $message);
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
}
?>
For table related looping and count of rows you may use the following
if ($no_of_users > 0) {
?>
<?php
while ($row = mysql_fetch_array($users)) {
Maybe cURL is the thing you're looking for.
For every row you could open a connection to send_message.php and pass the data you want.
Otherwise you could just include the send_message.php, but I would not recomment that.
EDIT
As you request, here is a VERY BASIC example:
<?php
$curlPostfields = array(
'field1'=>$value1,
'field2'=>$value2,
);
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, 'send_message.php');
curl_setopt($curlHandler, CURLOPT_HEADER, false);
curl_setopt($curlHandler, CURLOPT_POST, true);
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $curlPostfields);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curlHandler);
You could pack this in an own function and just call this function for every row of your table.

Php - find multiple strings inside code (from cURL)

I want to extract a "name" and an "ID" from a table which is loaded via a url. the table always contain different values.
One table could be this one: https://www.lectio.dk/lectio/262/FindSkema.aspx?type=stamklasse
i want to take every name and the id in the link its pointing to.
ex: name: 1m/id: 4514546468 (id from link: https://www.lectio.dk/lectio/262/SkemaNy.aspx?type=stamklasse&klasseid=4514546468)
how do i filter everything away but the things i need ? i get the source code with cURL and want to filter away the code so i have what i need left.
i did this whit a list with always fixed values, but since the table is always with different values i cant use the same code:
<?php
$ch = curl_init("http://www.lectio.dk/lectio/login_list.aspx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
$output = curl_exec($ch); // do it!
curl_close($ch); // close handle
$expld = explode("<a", $output);
$list = array();
$remove = array("/", "d");
$removefrom = array("/", "'", ">", "<");
foreach($expld as $key){
$gymnr = substr($key, 15, 3);
$gymnr = str_replace($remove, "", $gymnr);
$gymname = substr($key, 54);
$gymname = str_replace($removefrom, "", $gymname);
$gymname = substr($gymname, 0, -40);
$prelist = array($gymname, $gymnr);
$gymlist[] = $prelist;
};
unset($gymlist[0]);
foreach($gymlist as $school){
echo "<li data-id='".$school[1]."'>".$school[0]."</li>";
}
?>
I think i can use regex to filter this, but i don't know enough about it, i need examples or solutions.

How To Insert Links Scraped With DOM Into A MySQL Database? (or what am I doing wrong?)

I am putting together a php script that pulls html using curl, copies it into new pages and saves the page names. All that works, but I also want to collect the urls on the page and enter them into a database. From my research, it looks like DOM is the best way to do that. However I get "Error, insert query failed" when I include DOM in my code. Here is where I am getting the DOM code. I suspect this is a database issue.
DOM, PHP and MySQL are new to me, so any comments, pointers or suggestions would be helpful and appreciated.
Any comments on the overall approach, or suggestions of alternative, are also quite welcome. I am not entirely convinced that DOM is best for scraping urls from html.
<html>
<body>
<?
$urls=explode("\n", $_POST['url']);
$proxies=explode("\n", $_POST['proxy']);
for ( $counter = 0; $counter <= 6; $counter++) {
for ( $count = 0; $count <= 6; $count++) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$urls[$counter]);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($ch, CURLOPT_PROXY,$proxies[$count]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_exec ($ch);
$curl_scraped_page = curl_exec($ch);
$FileName = rand(0,100000000000);
$FileHandle = fopen($FileName, 'w') or die("can't open file");
fwrite($FileHandle, $curl_scraped_page);
$dom = new DOMDocument();
#$dom->loadHTML($curl_scraped_page);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
$hostname="****";
$username="****";
$password="****";
$dbname="leadturtle";
$usertable="happyturtle";
$con=mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($dbname ,$con);
function storeLink($url) {
$query = "INSERT INTO happyturtle (time, ad1, ad2) VALUES ('$FileName','$url', '$gathered_from')";
mysql_query($query) or die('Error, insert query failed');
}
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
storeLink($url,$target_url);
}
mysql_close($con);
fclose($FileHandle);
curl_close($ch);
echo $FileName;
echo "<br/>";
}
}
?>
</body>
</html>
You are not escaping the values in your SQL query.
If your strings parameters contain a ' it'll will lead to syntax error (best case).
But it can also lead to source injection and big security hole (http://xkcd.com/327/ :)!
First check your input.
Please add hte error message in your question.

Categories