PHP - Report Generation In Php
Hi guys, this is very urgent. Can anyone help me out.....
I want to generate reports using php and MySQL. I have one table which includes customer_id, full_name, name_with_initials, address, contact_number and gender fields. I want to print the details of all the records of the table. It should be good if results will come on a PDF format. Thanks, Similar TutorialsThis topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=314453.0 I need to email this report but I don't know where to start
I have included the report code.
<html> <head> <title>Customer Load Report</title> </head> <body> <h1>Customer Load Report</h1> <?php $custid=$_POST["Cust_ID"]; $connect =odbc_connect("removed"); if(!$connect) { exit("Connection Failed: " . $connect); } $sql="SELECT m1_DC.dbo.organizationlocations.cmlName ,m1_DC.dbo.SalesOrders.OMPSHIPPINGMETHODID ,m1_DC.dbo.SalesOrders.UOMPTRUCKNUMBER ,m1_DC.dbo.SalesOrders.ompCustomerPO ,m1_DC.dbo.SalesOrders.UOMPTOTALBOXCOUNT ,m1_DC.dbo.SalesOrders.UOMPVOLUMETOTAL ,m1_DC.dbo.organizationlocations.CMLADDRESSLINE1 ,m1_DC.dbo.organizationlocations.CMLADDRESSLINE2 ,m1_DC.dbo.organizationlocations.CMLCITY ,m1_DC.dbo.organizationlocations.CMLSTATE ,m1_DC.dbo.organizationlocations.CMLPOSTCODE ,m1_DC.dbo.SalesOrders.OMPREQUESTEDSHIPDATE ,m1_DC.dbo.SalesOrders.ompSalesOrderID ,convert(varchar(10),m1_DC.dbo.SalesOrders.ompRequestedShipDate,110) as ShipDate FROM m1_DC.dbo.SalesOrders LEFT OUTER JOIN m1_DC.dbo.organizationlocations ON ompshiporganizationid = cmlorganizationid AND ompshiplocationid = cmllocationid WHERE m1_DC.dbo.SalesOrders.ompCustomerOrganizationID='$custid' and (ompOrderDate>=CONVERT(VARCHAR(10),DATEADD(day, -7, getdate()),110) or convert(varchar(10),m1_DC.dbo.SalesOrders.ompRequestedShipDate,110) >=getdate())"; $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } $data= ''; while (odbc_fetch_row($result)) { $cmlName=odbc_result($result,"cmlName"); $ompCustomerPO=odbc_result($result,"ompCustomerPO"); $UOMPTOTALBOXCOUNT=odbc_result($result,"UOMPTOTALBOXCOUNT"); $UOMPVOLUMETOTAL=odbc_result($result,"UOMPVOLUMETOTAL"); $CMLADDRESSLINE1=odbc_result($result,"CMLADDRESSLINE1"); $CMLADDRESSLINE2=odbc_result($result,"CMLADDRESSLINE2"); $CMLCITY=odbc_result($result,"CMLCITY"); $CMLSTATE=odbc_result($result,"CMLSTATE"); $CMLPOSTCODE=odbc_result($result,"CMLPOSTCODE"); $ompSalesOrderID=odbc_result($result,"ompSalesOrderID"); $ompRequestedShipDate=odbc_result($result,"ShipDate"); $data .= "<td style='text-align:left' > $ompCustomerPO</td>"; $data .= "<td style='text-align:left'> $UOMPTOTALBOXCOUNT</td>"; $data .= "<td style='text-align:left'> $UOMPVOLUMETOTAL</td>"; $data .= "<td style='text-align:left'> $CMLADDRESSLINE1</td>"; $data .= "<td style='text-align:left'> $CMLADDRESSLINE2</td>"; $data .= "<td style='text-align:left'> $CMLCITY</td>"; $data .= "<td style='text-align:left'> $CMLSTATE</td>"; $data .= "<td style='text-align:left'> $CMLPOSTCODE</td>"; $data .= "<td style='text-align:left'> $ompSalesOrderID</td>"; $data .= "<td style='text-align:left'> $ompRequestedShipDate</td></tr>"; } echo "<table><tr>"; echo "<th>PO</th>"; echo "<th>Box_count</th>"; echo "<th>Cubes</th>"; echo "<th>ADDRESSLINE</th>"; echo "<th>ADDRESS2</th>"; echo "<th>CITY</th>"; echo "<th>STATE</th>"; echo "<th>ZIP</th>"; echo "<th>Order_ID</th>"; echo "<th>Ship Date</th></tr>"; echo $data; odbc_close($connect); ?> </body> </html> Hi all, I have a few questions and like some input on how best to approach this, I have a form in which customers can order different size online ads, the form has fields such as customer name, sales rep name, date needed by etc, my issue is I want to be able to run a report on how many different size ads I'm building in a day or month, would using MySQL be my solution to this? My PHP form right now gathers the information entered and sends me an email. Good day, How can I create a pdf report on my web page pulling out data from my database. I have never done this before I just need an idea. Dear All, Below is a php file for my website invitacoach.com I need to issue passwords myself to members who have already paid up for my services...of which they will then be able to access the advantages of a members area which include Videos, Audios and other publications. Which part of my code am i to edit Below is the SQL and register.php code. SQL CREATE TABLE users ( userid int(25) NOT NULL auto_increment, first_name varchar(25) NOT NULL default '', last_name varchar(25) NOT NULL default '', email_address varchar(25) NOT NULL default '', username varchar(25) NOT NULL default '', password varchar(255) NOT NULL default '', info text NOT NULL, user_level enum('0','1','2','3') NOT NULL default '0', signup_date datetime NOT NULL default '0000-00-00 00:00:00', last_login datetime NOT NULL default '0000-00-00 00:00:00', activated enum('0','1') NOT NULL default '0', PRIMARY KEY (userid) ) TYPE=MyISAM COMMENT='Membership Information'; REGISTER.PHP <? include 'db.php'; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $info = $_POST['info']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){ echo 'You did not submit the following required information! <br />'; if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } include 'join_form.html'; // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's time to create the account! */ /* Random Password generator. http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php We'll generate a random password for the user and encrypt it, email it and then enter it into the db. */ function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = md5($random_password); // Enter info into the Database. $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "Your Membership at invitacoach.com!"; $message = "Dear $first_name, Thank you for registering at our website, http://www.invitacoach.com You are two steps away from logging in and accessing our exclusive members area. To activate your membership, please click he http://www.invitacoach.com/test/activate.php?id=$userid&code=$db_password Once you activate your membership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! Invita Coach Hi all, For a logging tool I need to make some automated reports. On 1 page it needs to give for 4 clients the amount of calls per month for the last 12 months. Also it needs to give the amount of calls for the employees per month for the last 12 months. I was hoping you could help me with a better solution than seperate queries. Gr Ryflex Hi, I have to build some reports based on mysql queries. Nothing fancy, just text, columns... There are a lot of paid softwares but I can't (and don't want to) spend any $$ right now... So, considering that I want very simple reports almost like a table with heading and subtotals, I should write it myself. But I don't know how (still...). I'm looking for tips, tutorials, ebooks... anything that explains how to make a very simply report. Regards, Pedro. 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 {} } ?> ok. this may make now sense at all, I will try to explain as best as I can. anyways, what I need is for a mysql query to run that will pull all data from table payment between certain days. Then all the rows will show, but I want only one row with each cart_id(there will be multiple) to show. After it does that, in a new column on a table, all the payment types with the amount will show with a slash between each one. I want all of this in a table generated from a php loop. maybe a visual represenation will be better. I hope the picture I attached makes a bit more sense. Hello everyone, I am interested in creating a site with similar capabilities to this one: http://www.inkpixi.com/item/Classic+University/A223/295/item.html On this site, enter your name name and hit "Preview". The artwork is created using your name as a variable and other parameters to define how the artwork looks. I have a bunch of variables and I want to generate images (dynamically) using these variables. Any ideas or suggestions on how they do this on InkPixi.com? Thank you in advance, Tim Hi all, sorry cos there is no code. please how can i generate pairs (in twos, threes, fours or five) from a given set of numbers. the numbers are to be typed in the form text field and when click generate(submit button) it brings out the pair of numbers. thanks in advance my form Code: [Select] <form id="form1" name="form1" method="post" action=""> <table width="100%" border="0" cellspacing="2" cellpadding="1"> <tr> <td width="21%">Input Numbers : </td> <td width="79%"><input name="numbers" type="text" id="numbers" size="50" /></td> </tr> <tr> <td> </td> <td><input name="generate" type="submit" id="generate" value="Generate" /></td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </form> Hi i am using a script to upload an image and resize it twice first to create the large image and then again to create a thumbnail. The large image is being created fine and is uploading ok. I'm using the following code to then make the thumbnail but it does not appear to be working ( well nothing is in the thumbnail image folder i expect it to be anyways) can anyone see anything obvious that i am doing wrong ? Many Thanks /////////////////////////// Create a Thumbnail of the Image //////////////////////////////////// list($width, $height) = getimagesize($upload_image); // this is the large image which has apready been uploaded $ratio = $height/$width; if($ratio >= '1') // portret { $ht_tmb = 150; $br_tmb = 150/$ratio; } else { // landscape $ht_tmb = 150*$ratio; $br_tmb = 150; } // create thumb $source = imagecreatefromjpeg($upload_image); // The large image already uploaded //--- resize uploaded file $resize = imagecreatetruecolor($br_tmb, $ht_tmb); imagecopyresized($resize, $source, 0, 0, 0, 0, $br_tmb, $ht_tmb, $width, $height); imagejpeg($resize, "gallery_images/small/" .$filenamefd); $image = imagecreatefromjpeg("gallery_images/small/" .$filenamefd); imagejpeg($image, "gallery_images/small/" . $filenamefd); // end of making thumb ///////////////////////////////////////////////////////////////////////////////////////////////// Hello, I have a database with the following tables: students groups exams examDay relation master detail ======= ===== ===== ======= ====== ====== ===== idStudent idGroup idExam idExDay idRelation idMaster idDetail idGroup groupName examName exDate idGroup idGroup idMaster studName idExDay idRelation idExam idExam idStudent coursesAtt idExDay I am trying to make a report from the Master and Detail tables that will have the table header like this: Group | Examination Date | Student Name | Exam1 | Exam2| .... | Exam n in which Exam1, Exam2,... are the exams names and they had to take the values from coursesAtt column. Is this possible? I could make a view (doing joins and group by) by the results will be displayed on row. That's why I ask for your help. Thanks I'm looking for a function that creates a random string that contains random letters, numbers and symbols. Also it needs to generate it in a way that there are no repeating characters. Any ideas? I have set this up with a form on another page so that they can generate a runescape stat signature, although there is something wrong, if they do not select a font it comes up with an error. Here is the Code: Code: [Select] <?php header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $user = ""; $img = ""; $fnt = ""; if(isset($_GET['user'])) { if(!empty($_GET['user'])) { $user = $_GET['user']; } } if(isset($_GET['img'])) { if(!empty($_GET['img'])) { $img = $_GET['img']; } else{$img='blue';} } else{$img='blue';} if(isset($_GET['fnt'])) { if(!empty($_GET['fnt'])) { $fnt = $_GET['fnt']; } else{$fnt='arial';} } else{$img='blue';} if(isset($_POST['user'],$_POST['img'],$_POST['fnt'])) { if(!empty($_POST['user'])) { $user=$_POST['user']; } if(!empty($_POST['img'])) { $img = $_POST['img']; } if(!empty($_POST['fnt'])) { $fnt=$_POST['fnt']; } } //Skill Grabs $order = array("Overall", "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction", "Summoning", "Dungeoneering"); $get = file_get_contents("http://hiscore.runescape.com/index_lite.ws?player=$user"); $get = explode("\n", $get); $i = 0; foreach ($order as $key => $value) { $value = strtolower($value); $temp = explode(",", $get[$i]); $temp = array("rank" => $temp[0], "level" => $temp[1], "exp" => $temp[2]); $stats[$value] = $temp; $eval = "\$$value = array(\$temp[\"rank\"], \$temp[\"level\"], \$temp[\"exp\"]);"; eval($eval); $i++; } //End Skill Grabs $image = imagecreatefrompng("http://slay2day.x10.mx/highscores/signatures/".$img.".png"); $font = "/fonts/".$fnt.".ttf"; $color = imagecolorallocate($image, 255,255,255); ImageTTFText ($image, "7", 0, 280, 10, $color, "/fonts/arial.ttf","Slay2day"); ImageTTFText ($image, "12", 0, 240, 55, $color, $font,$user); if(is_numeric($overall[0])) { if($overall[0]==-1) { ImageTTFText($image, "11", 0, 230, 105, $color, $font,"2000000+"); } else { ImageTTFText($image, "11", 0, 240, 105, $color, $font,$overall[0]); } } else { ImageTTFText($image, "11", 0, 230, 105, $color, $font,"2000000+"); } ImageTTFText ($image, "10", 0, 27, 20, $color, $font,$attack[1]); ImageTTFText ($image, "10", 0, 27, 42, $color, $font,$strength[1]); ImageTTFText ($image, "10", 0, 27, 64, $color, $font,$defence[1]); ImageTTFText ($image, "10", 0, 27, 88, $color, $font,$hitpoints[1]); ImageTTFText ($image, "10", 0, 27, 114, $color,$font,$ranged[1]); ImageTTFText ($image, "10", 0, 70, 20, $color, $font,$prayer[1]); ImageTTFText ($image, "10", 0, 70, 42, $color, $font,$magic[1]); ImageTTFText ($image, "10", 0, 70, 64, $color, $font,$cooking[1]); ImageTTFText ($image, "10", 0, 70, 88, $color, $font,$woodcutting[1]); ImageTTFText ($image, "10", 0, 70, 114, $color,$font,$fletching[1]); ImageTTFText ($image, "10", 0, 117, 20, $color, $font,$fishing[1]); ImageTTFText ($image, "10", 0, 117, 42, $color, $font,$firemaking[1]); ImageTTFText ($image, "10", 0, 117, 64, $color, $font,$crafting[1]); ImageTTFText ($image, "10", 0, 117, 88, $color, $font,$smithing[1]); ImageTTFText ($image, "10", 0, 117, 114, $color,$font,$mining[1]); ImageTTFText ($image, "10", 0, 162, 20, $color, $font,$herblore[1]); ImageTTFText ($image, "10", 0, 162, 42, $color, $font,$agility[1]); ImageTTFText ($image, "10", 0, 162, 64, $color, $font,$thieving[1]); ImageTTFText ($image, "10", 0, 162, 88, $color, $font,$slayer[1]); ImageTTFText ($image, "10", 0, 162, 114, $color,$font,$farming[1]); ImageTTFText ($image, "10", 0, 212, 20, $color, $font,$runecraft[1]); ImageTTFText ($image, "10", 0, 212, 42, $color, $font,$construction[1]); ImageTTFText ($image, "10", 0, 212, 64, $color, $font,$hunter[1]); ImageTTFText ($image, "10", 0, 212, 88, $color, $font,$summoning[1]); ImageTTFText ($image, "10", 0, 212, 114, $color,$font,$dungeoneering[1]); header("Content-type: image/png"); imagepng($image); imagedestroy($image); //Logging $url = getenv("HTTP_REFERER"); // connect to the database include('connect-db.php'); //variables date_default_timezone_set('Pacific/Auckland'); $datepickerbox = $_POST['datepickerbox']; $datepickerbox = date("Y-m-d H:i:s", time($datepickerbox)); echo $datepickerbox; // save the data to the database mysql_query("INSERT signature SET user='$user', img='$img', time='$datepickerbox', url='$url', font='$fnt'") or die(mysql_error()); //End Logging ?> if they do not have a font i get: Code: [Select] Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/slay2day/public_html/highscores/signatures/signature.php on line 130 but of they dont choose a font i want it to use arial... This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=314049.0 I am in the process of trying to create a pedigree website (php/mysql)...
I want to be able to calculate a dog's inbreeding coefficient on 10 generations.
I am so not sure where to even begin.
I have a database table:
dogs:
Fields: id name sireid damid
equation:
FX = å [ (½) n1+n2+1 (1 + FA)]
http://www.highflyer...coefficient.htm
Can someone give me a starting point?
Do I need to learn bianary trees? could I do this with an array?
Thanks
Edited by Triple_Deuce, 20 November 2014 - 01:27 PM. Hello i am working on an application where i want to count from a selected date to another date and query all entries my database right now is composed of the following sales_id barcode_id student_id type of lunch date i have created the count per day, but now dont know how to go about to query the results and the count for the month. Code: [Select] $query = 'SELECT COUNT(*) FROM `sales` WHERE `tlunch` = 1 AND DATE(date) = CURDATE()'; $result = mysql_query($query) or die('Sorry, we could not count the number of results: ' . mysql_error()); $free = mysql_result($result, 0); has any one done something similar |