KC PUG to partner with the O’reilly User Group Program

In an effort to get more exposure, door prises and some extra information, the PHP User Group of Kansas City has been submitted to the O’Reilly & Associates User Group program. I think we are still awaiting “final approval” but as we have been meeting for quite some time now…well, I’ll let you know when I hear anything. For now, I’ve attached an email detailing some of the benefits once we are “approved.”
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.

Taking the step from personal to distributed

I keep creating scripts that other people want to use… In creating them, I basically did whatever I needed to to bend them into shape to do what I wanted… In order to distribute them to others, I pretty much have to set up everything myself… Obviously, this creates problems – even people who know me have a hard time giving me root access to their mysql db and such…

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

This month we will about a little class for generating reports using php. If you are really interested in new and exciting ways to separate your data layer from your presentation layer…read on.

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

Is there a php topic that you have been just itching to learn? Maybe something that you think would be of great help to the rest of our PHP loving community? Speaking at the KCPUG is a great way to make friends and gain experience. The “usual” speakers are just swamped this month, so this would be a great time to volunteer. 😉

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

Like him or not (I personally do), Harry Fuecks always has pleanty of great info on his site: phppatterns.com. There is no exception this week. He has just posted a flury of articles on using php to write SOAP/WSDL clients, SOAP servers and all kinds of other sudsy goodness. Read more for the direct links, or just go to his site: phppatterns.com

Mixed output and timing

Right, so I learned to code mixed html/php the sloppy way, switching back and forth whenever the mood struck. Lately, I’ve been realizing what a pain it is to figure out what’s where when something needs to
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’ve started working with larger datasets, so I added a timer function to display the time it took to generate each page in the footer…. I ran my old page a few times, and saw consisted 4+ second generation times. I changed it to the pseudo-template, and I’m getting consistent .2 second times.

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 .= ”

” . $myrow[“id”] . ”
“;
$out .= ”

” . $myrow[“title”] . ”
“;
$out .= ”

” . $myrow[“artist”] . ”
“;
$out .= ”

” . $myrow[“bpm”] . ”
“;
$out .= ”

” . $myrow[“genre”] . ”
“;
$out .= ”

” . $myrow[“stuff”] . ”
“;
$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

There is a new free PHP IDE available from a company called Maguma. It is for windows 98, Me, 2000, and XP. If you download the complete version it installs PHP 4.3 on your machine and it adds debugging functionality to the IDE. Sounds pretty nifty. I downloaded it the other day on my home computer but haven’t really tried it out yet. If anyone is looking for a free PHP development program with advanced functionality you might want to try it and let us know what you think.

Remember: This is your site!

Just wanted to remind our viewers that commenting on articles is HIGHLY encouraged. This site (as well as our group) exists to learn and discuss PHP concepts and “best” practices.

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