Subject: O'Reilly User Group Registration Date: 28 Apr 2003 07:48:53 -0700 Thanks for registering for the O'Reilly User Group Program. Your application has been submitted for approval. Explanation of program benefits: Review copies: O'Reilly offers free review copies of our books to qualified user groups. As the group contact, you may request a free review copy for your newsletter or web site. Requests for review copies MUST be submitted by you, as the contact of your group. If you wish for the review copy to be shipped to someone other than yourself, please supply the name, address and phone number of that person for shipment. Once a review of a book has been written, please send us a copy. Discounts: Your group members are entitled to a 20% discount on O'Reilly products purchased directly from us. Information for placing an order is provided on the discount flyers that will be shipped to you, upon acceptance to the program. Your members are also entitled to a 20% discount on O'Reilly conferences and tutorials. Other special discount offers may also be forwarded to your group from time to time. Other benefits: In addition, we regularly donate books and other promotional items for raffles or auctions to help your group raise money, or for meeting door prizes. On a quarterly basis, we'll send our latest catalog. Some of our authors are willing to speak at user group meetings--let us know if you are interested and well do what we can to help you arrange speakers. We'll also send you links to articles, tips, and news from the O'Reilly web site: www.oreilly.com and from the O'Reilly Network: www.oreillynet.com when we think the topics may interest you. Following verification of your registration information, we'll send your group a "Welcome Package" which includes an O'Reilly gift, 20% discount flyers, and our latest catalog. Please allow at least 6 weeks for delivery. What you can do for O'Reilly (not required): *Post an O'Reilly User Group Program banner to your web site, which you can find at: http://ug.oreilly.com/banners/ Please have the banner link back to www.oreilly.com. *If you don't have a web site, but you do have a newsletter, please print our sponsorship information in your newsletter. We can provide logo art upon request. *Encourage your members to review our books and post the reviews on your site or newsletter--making sure to notify me when the reviews are available. If you don't have a newsletter, please provide information to your group about O'Reilly products and UG Program benefits to your group email list.
Yearly Archives: 2003
Taking the step from personal to distributed
So what I’d like to see is a discussion of guidelines on how to package your php/mysql solutions for distribution so that it’s easier on the other end to get them up and running.
Part of this would be proper coding and commenting to begin with, I’m sure… But scrubbing existing code is a part of it as well. Are there any helpful functions, code bits, etc that ease the process? Any other helpful hints on how to accomplish this?
April Meeting – PHPReports
I was a bit pressed for time, so most of this content was taken either from the README or the phpreports site. The readme really is an excellent tour of the system, so if you are interested in how to use PHPReports, I would highly recommend you read it. Now, with that out of the way…
Requirements
You will need PHP compiled with XML/XSLT support. The PHPReports author uses the Sablotron libs in his work and examples.
Hello World
The PHPReports version of the classic Hello World, would be a simple table of database information. Lets take a look at the PHPReports Simple Sample before we get to far.
Document Structure
First off, we need to talk terminology. The author defines three key divisions or sections of a report:
- The Document Layer
- The Page Layer
- The Group Layer
The author describes these best:
You just have one document layer, one page layer (you can have a lot of pages, but just one page layer to configure) and some group layers.
All these layers collect information about the data on your report, like the number of lines, statistics about the fields and so on.
The document layer stores ALL these statistics, and stores it till the report end.
The page layer stores it till the page end, and reset it there.
The group layer stores it till the end of group, (where group is a set of data defined by a break expression, which could be any kind of field contained on your data set.)
So, to visualize it in ascii art, we might use something like this:
+----------------------------------+
| DOCUMENT_LAYER |
+----------------------------------+
| HEADER |
| |
| +------------------------------+ |
| | PAGE_LAYER | |
| +------------------------------+ |
| | HEADER | |
| | | |
| | +--------------------------+ | |
| | | GROUP LAYER | | |
| | | break expression A | | |
| | +--------------------------+ | |
| | | HEADER | | |
| | | FIELDS | | |
| | | | | |
| | | +----------------------+ | | |
| | | | GROUP LAYER | | | |
| | | | break expression A,B | | | |
| | | +----------------------+ | | |
| | | | HEADER | | | |
| | | | FIELDS | | | |
| | | | FOOTER | | | |
| | | +----------------------+ | | |
| | | FOOTER | | |
| | | | | |
| | +--------------------------+ | |
| | | |
| | FOOTER | |
| +------------------------------+ |
| |
| FOOTER |
+----------------------------------+
Or, if you prefer something a bit less abstract:
+---------------------------------------+----+
| John Doe Enterprises |////+--- document layer
| Sales Report |////|
+------+--------------------------------+----+
| city | <city goes here> |\\\\|
+------+-+------+-------------+---------+\\\\|
| id | name | product | $ |\\\\|
+------+--------+-------------+---------+\\\\+--- group layer
| <id> | =name= | <product> | <value> |\\\\|
+------+--------+-------------+---------+\\\\|
| total | <total> |\\\\|
+-----------------------------+---------+----+
| page total | <total> |////+--- page layer
+-----------------------------+---------+----+
| report total | <total> |\\\\+--- document layer (again)
+-----------------------------+---------+----+
So what does my php script look like? It’s Massive right??
include 'PHPReportMaker.php';
$sql = "select ID,NAME,CITY,PRODUCT,VALUE from SalesLog order by ID";
$parm = Array();
makeReport( "sales.xml", "PHPReport.xsl", "user", "mypass",
"mydb", "mysql", $sql, $parm );
Or…If you prefer the “cleaner” OO form:
<?php
include 'PHPReportMaker.php';
$sql = "select ID,NAME,CITY,PRODUCT,VALUE from SalesLog order by ID";
$oRpt = new PHPReportMaker();
$oRpt->setXML("sales.xml");
$oRpt->setUser("user");
$oRpt->setPassword("mypass");
$oRpt->setConnection("mydb");
$oRpt->setDatabaseInterface("mysql");
$oRpt->setSQL($sql);
$oRpt->run();
?>
sales.xml – The format spec for our report
You know that that would just be too easy, right. Do you see the “sales.xml” string above? That points to an xml file that contains the format spec for our report. Think of it as a template for our data.
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<REPORT>
<TITLE>Sales eport</TITLE>
<BACKGROUND_COLOR>#FFFFFF</BACKGROUND_COLOR>
<PAGE BORDER="1" SIZE="25" CELLSPACING="0" CELLPADDING="5" WIDTH="500">
<HEADER>
<ROW>
<COL COLSPAN="5">John Doe Enterprises</COL>
</ROW>
<ROW>
<COL COLSPAN="5">Sales Report</COL>
</ROW>
</HEADER>
<FOOTER>
<ROW>
<COL ALIGN="RIGHT" COLSPAN="4">page total</COL>
<COL ALIGN="LEFT" NUMBERFORMATEX="2" TYPE="EXPRESSION">$this->getSum("value")</COL>
</ROW>
</FOOTER>
</PAGE>
<GROUPS>
<GROUP NAME="maingroup">
<FIELDS>
<ROW>
<COL>id</COL>
<COL>name</COL>
<COL>city</COL>
<COL>product</COL>
<COL>value</COL>
</ROW>
</FIELDS>
</GROUP>
</GROUPS>
</REPORT>
This xml might show us a report that looks a lot like the following:
Where’s the REAL code?? Some more complete examples
There is a how-to example on the phpreports website that illustrates this topic. It also includes the complete XML file for generating the report.
There are a host of other Samples available on their site.
Be sure to check out their Super Swanky Report as well as the Debugging section. Yes, it has it’s own debugging helper.
Call for Speakers
I’ll even buy a can of soda (or bottle of water) from the machine for the brave soul who steps up to the plate! If you are serious about speaking, please comment to this thread by Apr 21st.
Thanks!!
EDITED: 2003-04-23 dholmes, Ok…So I whipped up a little something for this month. But the offer for a can of soda for just a little effort still stands. 😉 Feel free to “Sign-up” with your comments below. If you don’t want to speak but have an idea, please offer those too. Half the work is finding something to talk about. 🙂
SOAP and PHP; now on phppatterns
Mixed output and timing
change…. so I switched to just putting all my output into a variable, then outputting it in a pesudo-template at the end of the script.
I also read of a difference in using
“stuff $php_variable stuff”, which is slower than
“stuff ” . $php_variable . ” stuff”, so I changed that where
appropriate as well. Additionally, ‘stuff’ is also faster, but by a neglible amount.
Here’s the old code:
[code]
while ($myrow = mysql_fetch_array($result)) {
if (mysql_errno() != 0) {
echo “Error ” . mysql_errno() .”
“;
} else { // end if (mysql_errno() != 0)
?>
“;
} else { // end if (mysql_errno() != 0)
$out .= “
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
$out .= ”
“;
} // end else
} // end while ($myrow = mysql_fetch_array($result))
[/code]
This was for about 425 rows, I believe.
I had no idea it made THAT much of a difference… Guess I’ll be using that on everything now… If not switching over to SMARTY or some other true templating system.
Free PHP IDE w/ Debugger
March Meeting – PEAR::Cache
PHP on Mac OS X
Remember: This is your site!
So if you want to comment on a presentation, ask a related question, etc…please feel free to post a comment on the related article. This site is for you: The PHP community of Kansas City. We are all learning, so criticism and feedback are always welcome.
– Dan