Jump to content


Photo

Big Confusing PHP problem


  • Please log in to reply
27 replies to this topic

#21 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 30 May 2007 - 03:59 AM

Well you have unserialized the cookie which is leaving you an array of values. So you will need to convert your words into a format that can be accepted by the pdf creator, if you want a comment seperated string of the words, then do:

$words = unserialize( $_COOKIE['cookie1'] );
$words = implode( ', ', $words );

So when you do:

$pdf->addText(30,$y,$size,$words);

It $words would be equal to somthing like: word1, word2, word3, word4.....word19, word20

Which should fix it for you (depending on how the PDF creating class works)

Matt

#22 °•Guru•°

°•Guru•°

    Young Padawan

  • Members
  • Pip
  • 73 posts
  • Gender:Male
  • Location:Australia, Sydney

Posted 30 May 2007 - 06:52 PM

Great Thanks i've got the 20 words into the pdf now...now i just gotta figure out how to properly format this thing into a table and place the table of my bg image and DONE :D Hopefully soon :lol: Thanks

I'll post back if i'm having troubles :) thanks peeps!

OK one last problem...really confusing...here is some demo text from the readme doc for the class.

This code creates a simple 3 column table:
<?php
include ('class.ezpdf.php');
$pdf =& new Cezpdf();
$pdf->selectFont('./fonts/Helvetica.afm');
$data = array(
array('num'=>1,'name'=>'gandalf','type'=>'wizard')
,array('num'=>2,'name'=>'bilbo','type'=>'hobbit','url'=>'http://www.ros.co.
nz/pdf/')
,array('num'=>3,'name'=>'frodo','type'=>'hobbit')
,array('num'=>4,'name'=>'saruman','type'=>'bad
dude','url'=>'http://sourceforge.net/projects/pdf-php')
,array('num'=>5,'name'=>'sauron','type'=>'really bad dude')
);
$pdf->ezTable($data);
$pdf->ezStream();
?>

i currently have my words into a array called $data now...so atm what i am trying to achieve is to get a table with no headings just the words into the pdf....the table i am trying to create is 4 columns by 5 rows. Any ideas on how...i can send over the readme or whatever...sorry it's just really confusing to get the database $data array into the table.

There is not much help available for this class as it was made about 4 years ago a LONG time ago.

Cheers :)

ok an update i have the words in a table into the pdf document yay...only 1 thing formatting the table and setting a y position is a pain!!!....still trying to figure it out i think this problem will hurt the most as its the last before i'll be finished yay :)

Edited by rc69, 01 June 2007 - 02:16 PM.


#23 °•Guru•°

°•Guru•°

    Young Padawan

  • Members
  • Pip
  • 73 posts
  • Gender:Male
  • Location:Australia, Sydney

Posted 01 June 2007 - 02:14 AM

Hi all,

My Problem is that i can't get my array $txt to appear in the table i have split this into $chunks and i still can't manage to get it into the table cells....i want to have 1 word per cell and there is 20 words...Anyways here is my code:

<?php

if (!isset($words) || strlen($words)==0){
//$demotext='demo text';

$txt = explode( ',', $_COOKIE['cookie1'] );
$txt = implode( ',', $txt );


$string = $txt;
$chunks = spliti (",", $string, 20);
//print_r($chunks);

//$data = explode( ',', $data );
//$txt = array($txt);

//$words = unserialize( $_COOKIE['cookie1'] );
//print $_COOKIE['cookie1'];

//print $txt;
}

//require('fpdf.php');
require('html_table.php');

$html='<table border="1">
<tr>
<td width="190" height="125" align="center">cell 1</td><td width="190" height="125" >cell 2</td><td width="190" height="125" >cell 2</td><td width="190" height="125" >cell 2</td>
</tr>
<tr>
<td width="190" height="125" >cell 3</td><td width="190" height="125" >cell 4</td><td width="190" height="125" >cell 2</td><td width="190" height="125" >cell 2</td>
</tr>
<tr>
<td width="190" height="125" >cell 3</td><td width="190" height="125" >cell 4</td><td width="190" height="125" >cell 2</td><td width="190" height="125" >cell 2</td>
</tr>
<tr>
<td width="190" height="125" >cell 3</td><td width="190" height="125" >cell 4</td><td width="190" height="125" >cell 2</td><td width="190" height="125" >cell 2</td>
</tr>
<tr>
<td width="190" height="125" >cell 3</td><td width="190" height="125" >cell 4</td><td width="190" height="125" >cell 2</td><td width="190" height="125" >cell 2</td>
</tr>
</table>';

$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Image('pdfbg.jpg',0.4,0.3,0,0);
$pdf->SetY(148);
$pdf->WriteHTML($html);
$pdf->Text(40,160,$txt);
$pdf->Output();
?>

Thanks in advance
Hope someone can help :g[1]:

Cheers

#24 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 01 June 2007 - 04:09 AM

The quickest, but no means best way to be doing it:

<?php

$words = explode( ',', $_COOKIE['cookie1'] );

//require('fpdf.php');
require('html_table.php');

$html = '<table border="1">
	<tr>
		<td width="190" height="125">'.$words[0].'</td>
		<td width="190" height="125">'.$words[1].'</td>
		<td width="190" height="125">'.$words[2].'</td>
		<td width="190" height="125">'.$words[3].'</td>
	</tr>
	<tr>
		<td width="190" height="125">'.$words[4].'</td>
		<td width="190" height="125">'.$words[5].'</td>
		<td width="190" height="125">'.$words[6].'</td>
		<td width="190" height="125">'.$words[7].'</td>
	</tr>
	<tr>
		<td width="190" height="125">'.$words[8].'</td>
		<td width="190" height="125">'.$words[9].'</td>
		<td width="190" height="125">'.$words[10].'</td>
		<td width="190" height="125">'.$words[11].'</td>
	</tr>
	<tr>
		<td width="190" height="125">'.$words[12].'</td>
		<td width="190" height="125">'.$words[13].'</td>
		<td width="190" height="125">'.$words[14].'</td>
		<td width="190" height="125">'.$words[15].'</td>
	</tr>
	<tr>
		<td width="190" height="125">'.$words[16].'</td>
		<td width="190" height="125">'.$words[17].'</td>
		<td width="190" height="125">'.$words[18].'</td>
		<td width="190" height="125">'.$words[19].'</td>
	</tr>
</table>';

$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Image('pdfbg.jpg',0.4,0.3,0,0);
$pdf->SetY(148);
$pdf->WriteHTML($html);
$pdf->Text(40,160,$txt);
$pdf->Output();

?>


#25 Demonslay

Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 973 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 01 June 2007 - 10:57 AM

Wow, odd, Matt is usually the one who has all of the table row loops in his code, lol.

Here's a dynamic version that I bet Matt was just feeling too lazy to make at the time (don't blame him).
[codebox]<?php

$words = explode( ',', $_COOKIE['cookie1'] );

//require('fpdf.php');
require('html_table.php');

$columns = 4;
$word_count = count($words);

$html = '<table border="1">';

for($i = 0, $c = 1; $i < $word_count; $i++){
if($c == 1) $html .= "\n\t<tr>";
$html .= "\n\t\t".'<td width="190" height="125">'.$i.': '.$words[$i].'</td>';
if($c == $columns){
$html .= "\n\t</tr>";
$c = 1;
}
else
$c++;
}

$html .= "\n</table>";

$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Image('pdfbg.jpg',0.4,0.3,0,0);
$pdf->SetY(148);
$pdf->WriteHTML($html);
$pdf->Text(40,160,$txt);
$pdf->Output();

?>[/codebox]

Tested myself (other than the PDF construction bit of course), should work just fine for you.

#26 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 01 June 2007 - 11:26 AM

Yea I really couldn't be bothered, just did the easier option :)

#27 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 01 June 2007 - 02:15 PM

Matt, you also forgot, "please stick to one topic." And remember, the edit feature is there for a reason Guru.

$c = 1;
  }
  else
	$c++;
Demonslay, C++ is a language, not something to be used in PHP! :( (i'm joking btw).

Edited by rc69, 01 June 2007 - 02:16 PM.


#28 °•Guru•°

°•Guru•°

    Young Padawan

  • Members
  • Pip
  • 73 posts
  • Gender:Male
  • Location:Australia, Sydney

Posted 03 June 2007 - 08:29 PM

Cheers guys that's worked fine now ;)

Thanks heaps for all the help ppl :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users