PHP - Printing A Script
Hi,
I really need to find a way to print the code below in php. Code: [Select] <script> $(document).ready(function() { $.sticky('The page has loaded!'); }); </script> i tried Code: [Select] print"<script> $(document).ready(function() { $.sticky('The page has loaded!'); });"; </script> any help would be great. Similar TutorialsI have 64 rows of players and want each User to be able to choose to bookmark an player, as well as unbookmark it too. I have a bookmark table set up, and each time a User decides to bookmark(+) or unbookmark(-) an player a row is created in the data table. (Matching the player ID and User ID) That's working fine. A query reads the most recent row for each player to determine if there is a + or - button next to each player. Testing the query and adding some dummy data, that part of it works too. However, the issue is the initial state, which I want to be a +. Once I go live, the table will be empty, nothing for the query to return/produce. How do I create an initial state of a + with no rows and have it not used or swapped out when Users start clicking + or -?
$query = "SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."'&&'". $id ."' = playerID ORDER BY b.id desc LIMIT 1 "; $results = mysqli_query($con,$query); echo mysqli_error($con); while($row = mysqli_fetch_assoc($results)) { echo $row['bookmark']; if($row['bookmark'] == 0) { echo '-'; // this is where a form goes to remove a bookmark } else { echo '+'; // this is where a form goes to add a bookmark } } I tried to get it with CASE, but I don't think that's the right path. I also looked at UNION. I was able to get it to produce an initial state of +, but it still printed the already made up sample data too (so I have three instances of ++ or +-). (Players 2, 4 and 4)
Here is the what the UNION query looked like: $query = "(SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."'&&'". $id ."' = playerID ORDER BY b.id desc LIMIT 1) UNION (SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."' ORDER BY p.id desc LIMIT 1) ";
Hi there, I'm new in PHP, my output is in at table, I designed it already, now I want to print it..how can I do that ? do i need JS ? hi everyone I have a small user & business Directory and for it, I use a .htaccess ReWrite. My .htaccess file looks like Code: [Select] RewriteEngine On RewriteRule ^([^/.]+)$ index.php?q=$1 [QSA,L] so basically when I run Code: [Select] http://localhost/Johnsons/ then it treats that like Code: [Select] http://localhost/index.php?q=Johnsons I then do a PHP Query to find the result, I use the following; print "You looked up $_GET['q']"; $result = mysql_query("SELECT `name` FROM `directory` WHERE `name` = '".$_GET['q']."'"); while($row = mysql_fetch_array($result)) { print $row['name']; } this all works fine. The problem I now have is that I have been sent some new data in a SQL database import file and it contains entries such as Dugāriy T-ī-Corā but when I try and run http://localhost/Dugāriy/ or http://localhost/T-ī-Corā/ it does not return the correct value and instead it either misses characters or it exchanges one character for another, (ā is swapped "a" as an example). It seems this is due to a mix of Special Characters & Accents within words such as ā ū ī I have tried altering the META charset tag without any luck, I have also tried print utf8_encode($_GET['q']); print urlencode($_GET['q']); but nothing seems to work. Any idea on how I can solve this? Thanks very much J I have a directory that I would like to allow users to print to PDF format for download. How can I do this and where do I start? I have the following php script and get data from a database and prints in on a page however it does not print a carriage return. Why can this be? The script: <?php include "database.inc"; mysql_select_db("php", $connection); $result = mysql_query("SELECT * FROM orders", $connection); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { foreach ($row as $attribute) print "($attribute)"; print "\n"; } ?> hello all, i know that php is server side. if i have a printer attached to the server, can i have users press a button and have it print there? Hello,
I am trying to print the invoice in pdf, using fpdf. i am not getting how to do it. I am able to display line items , but its not in proper format. I tried changing X, Y positions, but its not going into my head . Also i want to display Logo and address in left side, invoice number and order date in right side.
Here is the code i have done so far... Please please help me in this
<?php require('includes/fpdf/fpdf.php'); //Connect to your database include("connect/DB_Connect.php"); $id = $_GET['id']; //Select the Products you want to show in your PDF file $result=mysql_query("select invoice_no, order_no, order_date, completion_date, artwork, customer_po, order_quantity, comments, order_amount from invoice where invoice_no='".$id."' ") or die(mysql_error()); $number_of_products = mysql_numrows($result); //Initialize the 3 columns and the total $column_order_date = ""; $column_order_no = ""; $column_artwork = ""; $column_cpo = ""; $column_order_quantity = ""; $column_order_amount = ""; $column_comments = ""; $total = 0; //For each row, add the field to the corresponding column while($row = mysql_fetch_array($result)) { $order_date = $row["order_date"]; $order_no = $row["order_no"]; $artwork = $row['artwork']; $cpo = $row['customer_po']; $oquantity = $row['order_quantity']; $oamount = $row['order_amount']; $comments = $row['comments']; //$price_to_show = number_format($row["Price"],',','.','.'); $column_order_date = $column_order_date.$order_date."\n"; $column_order_no = $column_order_no.$order_no."\n"; $column_artwork = $column_artwork.$artwork."\n"; $column_cpo = $column_cpo.$cpo."\n"; $column_order_quantity = $column_order_quantity.$oquantity."\n"; $column_order_amount = $column_order_amount.$oamount."\n"; $column_comments = $column_comments.$comments."\n"; //Sum all the Prices (TOTAL) $total = $total+$oamount; } mysql_close(); //Create a new PDF file $pdf=new FPDF(); $pdf->AddPage(); //Fields Name position $Y_Fields_Name_position = 20; //Table position, under Fields Name $Y_Table_Position = 26; //First create each Field Name //Gray color filling each Field Name box $pdf->SetFillColor(232,232,232); //Bold Font for Field Name $pdf->SetFont('Arial','B',12); $pdf->SetY($Y_Fields_Name_position); $pdf->SetX(5); $pdf->Cell(25,6,'Order Date',1,0,'L',1); $pdf->SetX(30); $pdf->Cell(50,6,'Graphixide Order No',1,0,'L',1); $pdf->SetX(75); $pdf->Cell(40,6,'Artwork',1,0,'L',1); $pdf->SetX(110); $pdf->Cell(20,6,'PO #',1,0,'L',1); $pdf->SetX(130); $pdf->Cell(20,6,'Quantity',1,0,'L',1); $pdf->SetX(150); $pdf->Cell(25,6,'Amount',1,0,'L',1); $pdf->SetX(175); $pdf->Cell(25,6,'Comments',1,0,'L',1); //Now show the 3 columns $pdf->SetFont('Arial','',12); $pdf->SetY($Y_Table_Position); $pdf->SetX(5); $pdf->MultiCell(25,6,$column_order_date,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(30); $pdf->MultiCell(80,6,$column_order_no,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(75); $pdf->MultiCell(40,6,$column_artwork,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(110); $pdf->MultiCell(20,9,$column_cpo,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(130); $pdf->MultiCell(20,6,$column_order_quantity,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(150); $pdf->MultiCell(75,6,$column_order_amount,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(175); $pdf->MultiCell(25,10,$column_comments,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(150); $pdf->MultiCell(130,6,'$ '.$total,1,'R'); //Create lines (boxes) for each ROW (Product) //If you don't use the following code, you don't create the lines separating each row $i = 0; while ($i < $number_of_products) { $pdf->SetX(45); $pdf->MultiCell(120,6,'',1); $i = $i +1; } $pdf->Output(); ?>Here is the output of this code ss.PNG 32.3KB 7 downloads is there a way to make a link or button that will print the current page, but only page 1, landscape with no headers or footers? or print between two tags? thanks Hi there! I found this code to parse a MySQL query to PDF, but it's for small address labels and I was wondering how to make it for 4x6 labels? <?php define('FPDF_FONTPATH','/home/directory/public_html/sub/font/'); require_once('fpdf.php'); //Connect to your database mysql_connect("localhost", "db_user","db_pw") or die ("Could not connect to database"); mysql_select_db("database_name") or die ("Could not select database"); $query = "SELECT employee_name, street_address, City, state, zip_code FROM employees ORDER BY `employee_name` "; $result = mysql_query($query) or die('Error, query failed'); $num_rows = mysql_num_rows($result); function PrintAddressLabels($result){ $pdf=new FPDF(); $pdf->Open(); $pdf->AddPage(); $pdf->SetFont('Arial','B',14); $pdf->SetMargins(0,0); $pdf->SetAutoPageBreak(false); $x = 0; $y = 0; $i=0; while (TRUE) { if ($row=$result[$i]) { //positions set above $LabelText = sprintf("%s\n%s %s\n%s, %s, %s", $row['employee_name'], $row['street_address'], $row['City'], $row['state'], $row['zip_code']); Avery5160($x,$y,&$pdf,$LabelText); $y++; // next row if ($y == 10 ) { // end of page wrap to next column $x++; $y = 0; if ($x == 3 ) { // end of page $x = 0; $y = 0; $pdf->AddPage(); } } $i++; //counter through result } else { // Error quit printing break; } { $pdf->Output('mailing_labels.pdf','D'); } ?> Does anyone know where I can find some good resources/tutorials that covers how to use the PDF stuff with PHP or know how I can change this up to match for 4x6 at all? Any help or info is greatly appreciated! Thanks! hi i have this code here and i was wondering how i could make it print out the values from my database using a drop down menu. i no this is probably very basic but im a real novice at php and sql. <?php mysql_connect('localhost', 'root', ''); mysql_select_db('charity_data'); $result = mysql_query('select * from donations'); ?> <select name="selectname"> <?php $i = 0; while ($i < mysql_num_fields($result)){ $fieldname = mysql_field_name($result, $i); echo '<option value="'.$fieldname.'">'.$fieldname.'</option>'; $i++; } ?> </select> Hi All, I am trying to generate a PDF report using the below code. the report is being generated perfectly. The problem that I face is that, while printing the report the browser disregards the "IF" condition that I have given in the code. Explanation : ----------------- It prints all the data in the MySQL database wherein I wanted the data to be printed only on a certain condition. How do I achieve this? Quote <?php mysql_connect('localhost','user','pass'); mysql_select_db('vaccine'); $array = mysql_query("SELECT cattle_n FROM vactbl"); $num_rows = mysql_num_rows($array); $array = mysql_query("SELECT * FROM vactbl"); $num_rows = mysql_num_rows($array); while($info = mysql_fetch_array( $array )) { $mas_date = $info['masdt']; $mas_time = strtotime($mas_date); $two_week = strtotime("+2 week"); $rpt_date = abs($two_week - $mas_time); if ($rpt_date >= 7776000) { require('mysql_table.php'); class PDF extends PDF_MySQL_Table { function Header() { //Title $this->SetFont('Arial','B',40); $this->Cell(0,6,'Cattle List',0,1,'C'); $this->Ln(10); //Ensure table header is output parent::Header(); } } //Connect to database $pdf=new PDF(); $pdf->AddPage(); //First table: put all columns automatically //$pdf->Table('select * from cattle_det order by no'); //$pdf->AddPage(); //Second table: specify 3 columns $pdf->AddCol('cattle_n',20,'Cattle','C'); $pdf->AddCol('masdt',40,'Mastitis Date', 'C'); $pdf->AddCol('fmdt',40,'FM Date','C'); $pdf->AddCol('onedt',40,'Vaccine1 Date','C'); $pdf->AddCol('twodt',40,'Vaccine2 Date','C'); $prop=array('HeaderColor'=>array(255,150,100), 'color1'=>array(210,245,255), 'color2'=>array(255,255,210), 'padding'=>2); $pdf->Table('select cattle_n, masdt, fmdt, onedt, twodt from vactbl order by cattle_n limit 0,10',$prop); $pdf->Output(); } else {} } ?> Here is my code...
<?php $to = "email@email.com"; //obviously not real $from = "noreply@domain.com"; //obviously not real $firstName = $_REQUEST['firstName']; $headers = "From: $from"; $subject = "Product Sheet Request"; /* $fields = array(); $fields{"firstName"} = "firstName"; $fields{"lastName"} = "lastName"; $fields{"email"} = "email"; $fields{"phone"} = "phone"; $fields{"affiliation"} = "affiliation"; $fields{"interest"} = "interest"; $fields{"productSheets"} = "productSheets"; $fields{"referredBy"} = "referredBy"; $fields{"additional"} = "additional"; */ $firstName = $_REQUEST['firstName']; $lastName = $_REQUEST['lastName']; $email = $_REQUEST['email']; $phone = $_REQUEST['phone']; $affiliation = $_REQUEST['affiliation']; $interest = $_REQUEST['interest']; if($interest == 'inclusion'){ $interest = 'Evaluating for inclusion in product'; } elseif($interest == 'general'){ $interest = 'Interested in the technology generally'; } elseif($interest == 'research'){ $interest = 'Performing market research'; } elseif($interest == 'solutions'){ $interest = 'Looking for competitive solutions'; } $referredBy = $_REQUEST['referredBy']; $additional = $_REQUEST['additional']; $productSheets[] = $_REQUEST['productSheets']; $sheets = print_r($productSheets); /* $body = "A user has requested product sheet(s). Please review their information and respond:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } */ $body = "A user has requested product sheet(s). Please review their information and respond:\n First Name: ".$firstName."\r Last Name: ".$lastName."\r Email: ".$email."\r Phone Number: ".$phone."\r Affiliation: ".$affiliation."\r Reason for Interest: ".$interest."\r Referred By: ".$referredBy."\r Additional Questions/Comments: ".$additional."\r Product Sheet(s) Requested: ".$sheets."\n "; $send = mail($to, $subject, $body, $headers); ?>I'm not quite sure how to display the values of the $productSheets array in the email message. Everytime it either outputs "Array" or "1". The $productSheets array is from a checkbox on a form. Everything else is working as expected. Hi, I want to echo an image depending on a value. This is the code I'm using Code: [Select] <?php if ($row_cliente_RS['estadofactura_titulo']) == 'yes' echo '<img src="img/pagada.jpg" width="70" height="15">'; ?>...but nothing echoes. What am I doing wrong? Thanks Hello, I need help with this issue, I am displaying <a href='index.php?cat=h & r'>text</a> when I do print $_GET['cat'] it only displays h, why ? Thanks I've got a database file from sqlite, there is a multidimensional array in it with 10 metals. I just want two print out each element in a table It won't get all the separate data inside a HEREDOC foreach ($product_prices as $metal => $prices) "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][28]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][36]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[wire][45]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][100]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][10]*$l_conv*$w_conv,4). "<tr><td>$metal</td><td align = 'right'>". round($prices[dust][1]*$l_conv*$w_conv,4). "</td></tr>"; Hi guys, I'm using this EOD thingi in order to print a table and get it PDF. I am using TCPDF and following their examples to get the PDF output. I need to print a php variable's value within the EOD. Can you please help me out. Below is the piece of code I'm running. Code: [Select] $tbl = <<<EOD <table cellspacing="0" cellpadding="1" border="1"> <tr> <td rowspan="4"><img src="images/m24.jpg"></td> <td align="right" width="150">From the desk of</td> <td>: $contat</td> </tr> <tr> <td align="right">E-Mail</td> <td>: $email</td> </tr> <tr> <td align="right">Telephone</td> <td>: $telephone</td> </tr> <tr> <td align="right">Mobile</td> <td>: $mobile</td> </tr> </table> EOD; the $variables are simply ignored. or even if I echo, there is no PHP value. Can you guys please shed some light on this issue. Pretty pleeeaaassseee The following generic code prints out a given table in my database, by first getting the fieldnames and putting them as the title of each column, and then getting the values. How do I change it so that if the name of the field is "password", the value will echo "----" instead of the password? $sql = "SELECT * FROM $tablename"; $result = mysql_query($sql) or die("Query failed : " . mysql_error()); $row = 1; ?> <table width="90%" border="1"><?php //the MYSQL_ASSOC gets field names instead of numbers while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row == 1) { ?><tr><?php foreach ($line as $col_key => $col_value) { ?><th><?php echo $col_key;?></th><?php } ?></tr><?php } ?><tr><?php foreach ($line as $col_value) { ?><td><?php echo $col_value;?></td><?php } ?></tr><?php $row++; I am using sprintf( mysql_insert_id()); to print primary key but I can save this in a varible and echo this. But I would like to know how to save this in to a session and use this one another page. Hi I have a problem that I must admit I have come across before but I can't remember the fix. When I do a simple select query then print it out using a while statement, I can't get it to print out the first record of my results. I am sure this is to do with the execute statement but I can't get it to work properly. I currently have test data in so I know this should bring out 6 records but it only lists 5 I am trying to print out information from a list. I thought I had this figured out but realized It was just printing out the same information over and over. This is from a Joomla website and I am using the J2store extension, just to give you the information from where this is coming from. So this is suppose to print out all the attributes from a single order. Each item in the order has any number of attributes that make it up. I am using it as an assembly site. So each assembly will have different attributes that make it up. (Hope that explains it good enough.) <?php JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_j2store/models'); $model = JModelLegacy::getInstance( 'OrderItemAttributes', 'J2StoreModel' ); ?> <?php foreach (@$items as $item) : ?> <?php //these are just printed to show the 5 different items in the same order echo $item->order_id; echo '<br />'; echo $item->orderitem_id; echo '<br />'; echo $item->orderitem_name; echo '<br />'; $model->setState( 'filter_orderitemid', $item->orderitem_id); $attributes = $model->getList(); foreach($attributes as $attribute) { if(!empty($attribute->orderitemattribute_value)) { echo $attribute->orderitemattribute_name.' : '.$attribute->orderitemattribute_value; echo '<br />'; } } echo '<br />'; ?> <?php endforeach; ?>This ends up printing out this: -------------------------------------------------------- 1402100770 49 16" Box to Stud Bracket with Open Back Box + Modular Duplex BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 52 3/4" Conduit Masonry Stub BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 53 3/4" Conduit Masonry Stub BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 51 MC Cable Whip Assembly BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 1402100770 50 Span Bracket with 4 SQ. Deep 1/2''-3/4'' KO's + Modular 2 Single BRACKET : B-Line BB7-16 BOX : Crouse Hinds TP40DPF Mud Ring (Choose an Option) : 3/4'' Rise Single Gang MC Cable (Choose an Option) : 12/2 (black,white,green) x 25' L Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector Device Color (Choose an Option) : White MC Connector (x2) : Crouse Hinds 38MCQ 12/2 Anti-Short (x2) : 12/2 Anti Short 11" Cable Tie (x2) : 11'' Cable Tie 4 Port Wago (x3) : Ideal Model 88 Device Protector Plate : B-Line BPR1 -------------------------------------------------------- The number '1402100770' is the order number. Which in that order there were 5 items purchased. The numbers for the orderitem_id are the correct numbers for the order number. The name is also the correct for the items that were in the order. The problem is when the attributes print out. It prints the same attributes for all 5 items purchased. It seems to be printing the first items attributes for all the items in the order. I can't figure out why the orderitem_id and orderitem_name all prints out correctly but when it prints of the attributes it just prints the same attributes for all the items in the order. |