searls03 Posted April 17, 2011 Author Share Posted April 17, 2011 none of the titles come up when it is present in database....... Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202727 Share on other sites More sharing options...
searls03 Posted April 17, 2011 Author Share Posted April 17, 2011 ok, so with the random code thing.......I am trying to expand my idea a bit...............how could I basically make like a barcode that is associated with the ticket.........this one would need to be stored in database with the event...............just trying to make this so it can't be4 forged too easily............can this be done? Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202729 Share on other sites More sharing options...
analog Posted April 17, 2011 Share Posted April 17, 2011 Whats assigning the titles their value? To make a the barcode first store the random string in a variable and then save is in the database and then use one of the barcode addons for FPDF to make the barcode like: http://www.fpdf.org/en/script/script5.php Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202731 Share on other sites More sharing options...
searls03 Posted April 17, 2011 Author Share Posted April 17, 2011 all those subevents should actually say title........still that is not the issue............to see full code, look at first post on page 2. Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202732 Share on other sites More sharing options...
searls03 Posted April 17, 2011 Author Share Posted April 17, 2011 pretty sure I messed this up for the barcode can you help: require('fpdf.php'); class PDF_EAN13 extends FPDF { function EAN13($x, $y, $barcode, $h=16, $w=.35) { $this->Barcode($x,$y,$barcode,$h,$w,13); } function UPC_A($x, $y, $barcode, $h=16, $w=.35) { $this->Barcode($x,$y,$barcode,$h,$w,12); } function GetCheckDigit($barcode) { //Compute the check digit $sum=0; for($i=1;$i<=11;$i+=2) $sum+=3*$barcode[$i]; for($i=0;$i<=10;$i+=2) $sum+=$barcode[$i]; $r=$sum%10; if($r>0) $r=10-$r; return $r; } function TestCheckDigit($barcode) { //Test validity of check digit $sum=0; for($i=1;$i<=11;$i+=2) $sum+=3*$barcode[$i]; for($i=0;$i<=10;$i+=2) $sum+=$barcode[$i]; return ($sum+$barcode[12])%10==0; } function Barcode($x, $y, $barcode, $h, $w, $len) { //Padding $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT); if($len==12) $barcode='0'.$barcode; //Add or control the check digit if(strlen($barcode)==12) $barcode.=$this->GetCheckDigit($barcode); elseif(!$this->TestCheckDigit($barcode)) $this->Error('Incorrect check digit'); //Convert digits to bars $codes=array( 'A'=>array( '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011', '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'), 'B'=>array( '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101', '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'), 'C'=>array( '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100', '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100') ); $parities=array( '0'=>array('A','A','A','A','A','A'), '1'=>array('A','A','B','A','B','B'), '2'=>array('A','A','B','B','A','B'), '3'=>array('A','A','B','B','B','A'), '4'=>array('A','B','A','A','B','B'), '5'=>array('A','B','B','A','A','B'), '6'=>array('A','B','B','B','A','A'), '7'=>array('A','B','A','B','A','B'), '8'=>array('A','B','A','B','B','A'), '9'=>array('A','B','B','A','B','A') ); $code='101'; $p=$parities[$barcode[0]]; for($i=1;$i<=6;$i++) $code.=$codes[$p[$i-1]][$barcode[$i]]; $code.='01010'; for($i=7;$i<=12;$i++) $code.=$codes['C'][$barcode[$i]]; $code.='101'; //Draw bars for($i=0;$i<strlen($code);$i++) { if($code[$i]=='1') $this->Rect($x+$i*$w,$y,$w,$h,'F'); } //Print text uder barcode $this->SetFont('Arial','',12); $this->Text($x,$y+$h+11/$this->k,substr($barcode,-$len)); } } function genRandomString($length = 100) { $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string =''; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } class PDF { //Page header function Header() { global $name; global $total; // get the variable $name1 into the scope of this function //Logo //Arial bold 15 $this->SetFont('Arial','B',15); //Move to the right $this->Cell(70); //Title $this->Cell(0,0,'Please bring this to the next Scout Meeting',0,0,C); //Line break $this->Ln(20); $this->Cell(0,0,'',1,0); $this->Ln(20); $this->cell(50,10, 'Registrant:', 1,0); $this->cell(50,10, 'Events:', 1,0); $this->cell(50,10, 'Price:', 1,0); $this->Ln(10); $this->cell(50,10,$name, 1,0); $this->cell(50,10, $events, 1,0); $this->cell(50,10,"$$total", 1,0); } //Page footer function Footer() { //Position at 1.5 cm from bottom $this->SetY(-15); //Arial italic 8 $this->SetFont('Arial','I',12); //Page number $this->Cell(0,10,genRandomString(),0,0,'C');} } //Instanciation of inherited class require('ean13.php'); $pdf=new PDF_EAN13(); $pdf=new PDF(); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->EAN13(80,40,'123456789012'); $pdf->Output(); $pdf->SetFont('Times','',10); $pdf->Output('ticket.pdf', 'I'); Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202734 Share on other sites More sharing options...
analog Posted April 17, 2011 Share Posted April 17, 2011 Looks like the titles are stored in the database as title1, title2, ect. Dose this not work: <?php $sql = ("SELECT * FROM Events WHERE eventid='$eventid' && userid='$userid'"); $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $event = $row['event']; $startdate = $row['startdate']; $enddate = $row['enddate']; $description = $row['description']; $location = $row['location']; $subevent1 = $row['title1']; $subevent1 = $row['title2']; $subevent3 = $row['title3']; $subevent4 = $row['title4']; $subevent5 = $row['title5']; $subevent6 = $row['title6']; } if (!empty($subevent1)) { echo "<br/>$subevent1"; } if (!empty($subevent2)) { echo "<hr><br/>$subevent2" ; } if (!empty($subevent3)) { echo "<hr><br/>$subevent3"; } if (!empty($subevent4)) { echo "<hr><br/>$subevent4"; } if (!empty($subevent5)) { echo "<hr><br/>$subevent5"; } if (!empty($subevent6)) { echo "<hr> <br/>$subevent6"; } if (!empty($title7)) { echo "<hr><br/>$title7"; } if (!empty($title8)) { echo "<hr><br/>$title8"; } ?> Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202735 Share on other sites More sharing options...
analog Posted April 17, 2011 Share Posted April 17, 2011 Whats the problem with the barcode? Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202736 Share on other sites More sharing options...
searls03 Posted April 17, 2011 Author Share Posted April 17, 2011 it works on the previous page............I mainly need to know how I can make that the value of $event.......... Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202737 Share on other sites More sharing options...
searls03 Posted April 17, 2011 Author Share Posted April 17, 2011 well for one I had no idea where to put what and 2, only the barcode is showing now.......... Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202739 Share on other sites More sharing options...
analog Posted April 17, 2011 Share Posted April 17, 2011 The previous page stores it in the DB here: $sql = "REPLACE INTO Events (name, event, eventid, userid, title1, title2, title3, title4, title5, title6, title7, title8, email, id, price1, price2, price3, price4, price5, price6, price7, price8) VALUES('$name','$event','$eventid','$userid','$title1','$title2','$title3','$title4','$title5','$title6','$title7','$title8','$email','$id','$price1', '$price2', '$price3','$price4','$price5','$price6','$price7','$price8')"; So you should be able to just select it out of the DB on the next page. For the barcode: <?php // code to popualte $total, ect. here. class PDF extends FPDF { function EAN13($x, $y, $barcode, $h=16, $w=.35) { $this->Barcode($x,$y,$barcode,$h,$w,13); } function UPC_A($x, $y, $barcode, $h=16, $w=.35) { $this->Barcode($x,$y,$barcode,$h,$w,12); } function GetCheckDigit($barcode) { //Compute the check digit $sum=0; for($i=1;$i<=11;$i+=2) $sum+=3*$barcode[$i]; for($i=0;$i<=10;$i+=2) $sum+=$barcode[$i]; $r=$sum%10; if($r>0) $r=10-$r; return $r; } function TestCheckDigit($barcode) { //Test validity of check digit $sum=0; for($i=1;$i<=11;$i+=2) $sum+=3*$barcode[$i]; for($i=0;$i<=10;$i+=2) $sum+=$barcode[$i]; return ($sum+$barcode[12])%10==0; } function Barcode($x, $y, $barcode, $h, $w, $len) { //Padding $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT); if($len==12) $barcode='0'.$barcode; //Add or control the check digit if(strlen($barcode)==12) $barcode.=$this->GetCheckDigit($barcode); elseif(!$this->TestCheckDigit($barcode)) $this->Error('Incorrect check digit'); //Convert digits to bars $codes=array( 'A'=>array( '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011', '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'), 'B'=>array( '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101', '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'), 'C'=>array( '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100', '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100') ); $parities=array( '0'=>array('A','A','A','A','A','A'), '1'=>array('A','A','B','A','B','B'), '2'=>array('A','A','B','B','A','B'), '3'=>array('A','A','B','B','B','A'), '4'=>array('A','B','A','A','B','B'), '5'=>array('A','B','B','A','A','B'), '6'=>array('A','B','B','B','A','A'), '7'=>array('A','B','A','B','A','B'), '8'=>array('A','B','A','B','B','A'), '9'=>array('A','B','B','A','B','A') ); $code='101'; $p=$parities[$barcode[0]]; for($i=1;$i<=6;$i++) $code.=$codes[$p[$i-1]][$barcode[$i]]; $code.='01010'; for($i=7;$i<=12;$i++) $code.=$codes['C'][$barcode[$i]]; $code.='101'; //Draw bars for($i=0;$i<strlen($code);$i++) { if($code[$i]=='1') $this->Rect($x+$i*$w,$y,$w,$h,'F'); } //Print text uder barcode $this->SetFont('Arial','B',12); $this->Text($x,$y+$h+11/$this->k,substr($barcode,-$len)); } //Page header function Header() { global $name; global $total; // get the variable $name1 into the scope of this function //Logo //Arial bold 15 $this->SetFont('Arial','B',15); //Move to the right $this->Cell(70); //Title $this->Cell(0,0,'Please bring this to the next Scout Meeting',0,0,C); //Line break $this->Ln(20); $this->Cell(0,0,'',1,0); $this->Ln(20); $this->cell(50,10, 'Registrant:', 1,0); $this->cell(50,10, 'Events:', 1,0); $this->cell(50,10, 'Price:', 1,0); $this->Ln(10); $this->cell(50,10,$name, 1,0); $this->cell(50,10, $events, 1,0); $this->cell(50,10, $total, 1,0); } //Page footer function Footer() { //Position at 1.5 cm from bottom $this->SetY(-15); //Arial italic 8 $this->SetFont('Arial','B',; //Page number $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); } } //Instanciation of inherited class $pdf=new PDF(); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->EAN13(10, 120, '38927923'); $pdf->SetFont('Arial','B',12); $pdf->Output('ticket.pdf', 'I'); ?> Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202753 Share on other sites More sharing options...
searls03 Posted April 18, 2011 Author Share Posted April 18, 2011 I figured I could, but I don't want there to be a huge gap if like there is title1 present and title8 present but not 2-7...........does this make sense? Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202764 Share on other sites More sharing options...
searls03 Posted April 18, 2011 Author Share Posted April 18, 2011 is this where globals should be? oh and error: Fatal error: Class 'FPDF' not found in /home/a6254834/public_html/ticket.php on line 51 class PDF extends FPDF { function EAN13($x, $y, $barcode, $h=16, $w=.35) { global $name; global $total; global $events; $this->Barcode($x,$y,$barcode,$h,$w,13); } Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202767 Share on other sites More sharing options...
searls03 Posted April 18, 2011 Author Share Posted April 18, 2011 and is there a way for just a random barcode for each different ticket? Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202768 Share on other sites More sharing options...
searls03 Posted April 18, 2011 Author Share Posted April 18, 2011 ok, i got the events piece figured out.........so how do I make it a random barcode? Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202779 Share on other sites More sharing options...
searls03 Posted April 18, 2011 Author Share Posted April 18, 2011 so how do I make this text field do the inpup of the random code thing? echo "<input name='barcode' type=\"text\" value=\" cell(0,10,genRandomString(),0,0,'C');\" />"; Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1202789 Share on other sites More sharing options...
searls03 Posted April 19, 2011 Author Share Posted April 19, 2011 ok, so with the barcode thing, how do I make it so that the 0 at start don't show up and the random number at end doesn't display. will use a form to submit 13 numbers to database that is generated when the form is submitted and then I use those numbers to make the barcode, but I need to get rid of the 5(i believe) randomly generated numbers at beginning and end. does this make sense? Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1203704 Share on other sites More sharing options...
searls03 Posted April 22, 2011 Author Share Posted April 22, 2011 how do I do that? Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1204844 Share on other sites More sharing options...
searls03 Posted April 29, 2011 Author Share Posted April 29, 2011 anything from there? Link to comment https://forums.phpfreaks.com/topic/233982-have-strings-in-documents/page/2/#findComment-1208282 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.