Sourceofarticles.com Menu
Newest Articles
Most Viewed Articles
Sourceofarticles.com RSS
Submit Article
Login
Signup
Search the articles

Articles Main Categories
Advice
Animals
Automobiles
Business
Career
Communications
Computer Programming
Computers
Entertainment
Environment
Family
Fashion
Finance
Food
Health & Medical
Home & Garden
Humor
Internet Business
Internet Marketing
Legal
Leisure & Recreation
Marketing
Other
Politics
Reference & Education
Religion
Self Improvement
Sports
Technology & Science
Travel
Writing
Subscribe
Receive alert message from us when new articles submitted to our site for free.

Enter your name

Enter your email

Syndicate

















Related Products
Pink Color Wood Flower Bead Bracelet 12 pcs Fashion New
US $0.99 (0 Bid)
End Date: Friday Nov-21-2008 10:02:45 PST
Bid now | Add to watch list

FASHION GOLD SKELETON MECHANICAL MEN BLK LEATHER WATCH
US $4.26 (0 Bid)
End Date: Friday Nov-21-2008 10:03:22 PST
Bid now | Add to watch list

14K HGE 7CT STRONG FASHION DIAMOND SIMULATED SZ5 RING
US $7.99 (0 Bid)
End Date: Friday Nov-21-2008 10:03:23 PST
Bid now | Add to watch list

Timex Fashion Classics 78677 Wrist Watch
US $18.00
End Date: Friday Nov-21-2008 10:03:57 PST
Buy It Now for only: US $18.00
Buy it now | Add to watch list

Surfer Fashion Jewelry Hemp Mens/Women Bracelet/Anklet
US $6.99 (0 Bid)
End Date: Friday Nov-21-2008 10:05:00 PST
Buy It Now for only: US $6.99
Bid now | Buy it now | Add to watch list

PLUS SIZE CAMISOLE/TANK WITH BUILT-IN BRA FASHION BUG1X
US $4.50 (0 Bid)
End Date: Friday Nov-21-2008 10:05:39 PST
Buy It Now for only: US $6.75
Bid now | Buy it now | Add to watch list

VINTAGE UNDER-LINERS #1821 BARBIE FASHIONS CLOTHES
US $15.50 (6 Bids)
End Date: Friday Nov-21-2008 10:05:39 PST
Bid now | Add to watch list

FASHION GIRL OPEL BICYCLE CYCLES DIE SIEGERIN POSTER RE
US $4.95 (0 Bid)
End Date: Friday Nov-21-2008 10:06:28 PST
Bid now | Add to watch list

FASHION WHITE SKELETON MECHANICAL MEN LEATHER WATCH
US $4.26 (0 Bid)
End Date: Friday Nov-21-2008 10:06:30 PST
Bid now | Add to watch list

New Fashion Men Dress Shoes Loafer Alligator Brown 8.5
US $22.99 (0 Bid)
End Date: Friday Nov-21-2008 10:06:50 PST
Buy It Now for only: US $27.99
Bid now | Buy it now | Add to watch list

*NEW* 4 - FASHION BUG 50% Any Item Coupons Dec 2009!
US $2.04 (4 Bids)
End Date: Friday Nov-21-2008 10:06:55 PST
Bid now | Add to watch list

Home::CGI

An Extensive Examination of the PHP:DataGrid Component: Part 1

Author : Dennis Pallett

An Extensive Examination of the PHP:DataGrid Component: Part 1

Introduction One of the most common tasks in PHP
is retrieving data from a database table, and creating a HTML
table to output that data. It's done in almost every project,
and it's usually a really boring task, because the code is
always nearly the same, but not just same enough to be able to
copy it.

It often looks some like this (in pseudo-code):

Create database connection Get data from a table Output
table header (<table) Loop through each records ... output
tr's and td's ... Output table footer (</table>)


It's a sad fact, but we've already written code like the above
hundreds of times. And for every project and script, you have to
do it again, again and again.

But why not use a solution that can do it for us? That's exactly
what PHP:DataGrid is.

What is
PHP:DataGrid?

PHP:DataGrid is the answer to the above problem. It's
basically a PHP component, that's very similar to the ASP.NET
DataGrid control. PHP:DataGrid will take care of all the boring
tasks leaving you the easy and interesting parts. Very little
PHP code is actually necessary for PHP:DataGrid, and you can
change its looks and layout using simple HTML tags.

The only downside of PHP:DataGrid is that it's not free. You
have to purchase it from TPG
PHP Scripts, but it's $24.99 for a Developer license, which
grants you permission to use it in all your personal projects,
and I certainly believe that the advantages far outweigh the
cost. Even only the time saved by PHP:DataGrid is already worth
the cost for me. (editor's note: use coupon code phpit
for a 10% discount!).

Let's have an actual look at PHP:DataGrid. If you don't want to
purchase the component yourself, then you can always have a look
at the demo's only.

The
Basics
To create a new datagrid, we must use the
php:datagrid tag. This tells the PHP:DataGrid component that a
datagrid must be shown. The only thing that we must set is the
name of the datagrid. This is a required attribute, and cannot
be left out. A simple datagrid looks like this:

<php:datagrid
name="test"></php:datagrid>


That's the only thing necessary to display a datagrid. But we're
forgetting one thing - we haven't binded any data to the
datagrid yet. If you forget to do this, nothing will be
displayed, except for an error.

Binding
Data
Binding data to a datagrid is really easy, and
requires only one line of real PHP code. The PHP:DataGrid
component automatically creates a variables called $_DATAGRID
(not a superglobal,
unfortunately). To bind data, you have to call the bind() method
on the $_DATAGRID variable, like so:
$_DATAGRID->bind('test', $data);
That's all! The
test datagrid will now be shown, with the data contained in the
$data variable. The $data variable must be an array that was
retrieved using mysql_fetch_array() and a loop (see the datagrid
example below if you're unsure about this) or similar format. In
any case, it should look like this:

Array ( [0] => Array ( [id] => 1 [title] => Item 1
[category] => 4 )

[1] => Array ( [id] => 2 [title] => Item 2 [category]
=> 7 )

[2] => Array ( [id] => 3 [title] => Item 3 [category]
=> 3 ) )


The above is a valid $data array. It won't accept any other
format, and an error will be shown if you do bind a different
format.

An
Example
The below code is a working example of a simple
datagrid. It retrieves the 10 latest tutorials from the
PHPit.net database, and shows it in a datagrid.
<?php

// Include PHP:DataGrid include ('/path/to/phpdatagrid.php');

// Connect to database $link = mysql_connect ('localhost', 'sa',
'[db-pass]');

// Select database mysql_select_db('phpit', $link);

// Do query and Get data $result = mysql_query ("SELECT
title, description, author, datetimestamp, filename FROM
tutorial ORDER BY datetimestamp DESC LIMIT 0, 10"); $data =
array(); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
array_push ($data, $row); }

// Bind data (THIS IS IMPORTANT) $_DATAGRID->bind ('test',
$data);

?> <html> <head> <title>PHP:DataGrid Demo
1</title> </head>

<body> <h1>PHP:DataGrid Demo 1</h1>
<p>Demonstrating a simple PHP:DataGrid, and nothing
more.</p>

<php:datagrid name="test"></php:datagrid>

<br /> <a
href="http://www.phpit.net/article/datagrid-1/";><
strong>« Return to the
article</strong></a> </body>
</html>
[ View live demo ]

As you can see little code is used for the datagrid. Most of the
code is actually spent on connecting to the MySQL database, and
getting the data. If you use any kind of database class, this
will be significantly easier.

If you have a look at the datagrid, you will notice that it
looks ugly, and pretty bad. That's because we haven't added any
styling at all. But that will have to wait until Part 2 of our
DataGrid series.

Summary
In this part of our DataGrid series, we've looked at the basics
of the PHP:DataGrid component: what it is, and how to put it on
our website. But it doesn't look pretty yet, and in the next
parts we'll be looking at creating a pretty datagrid, and talk
about more of its functions (e.g. templates, inline editing,
sorting and more!).


Click here to view the PHP:DataGrid Product Page Don't
forget - use coupon code phpit for a 10% discount!

Related articles


  1. 5 CGI Scripts You Must Use to Turn Your Site Into a Powerhouse
  2. Clever Profit Growth Software
  3. Why Aren't You Using CGI
  4. Use CGI to Automate Your Web Site
  5. CGI: What the Heck Is That?
  6. CGI Security Issues
  7. How to Stop Digital Thieves with CGI
  8. Quick Intro to PHP Development
  9. Better Writing: What Works and What Doesn't
  10. Password Protection and File Inclusion With PHP
  11. Autoresponders With PHP
  12. Track your visitors, using PHP
  13. PHP On-The-Fly!
  14. PHP and Cookies; a good mix!
  15. Screen scraping your way into RSS
  16. Mastering Regular Expressions in PHP
  17. ASP, CGI and PHP Scripts and Record-Locking: What Every Webmaster Needs To Know
  18. Open Source Scripts
  19. this is a test
  20. An Extensive Examination of the PHP:DataGrid Component: Part 1
  21. PHP:Form Series, Part 1: Validators & Client-side Validation
  22. Design an Online Chat Room with PHP and MySQL
More related feeds
An+Extensive+Examination+of+the+PHP:DataGrid+Component:+Part+1http://blogsearch.google.com/blogsearch_feeds?hl=en&q=An+Extensive+Examination+of+the+PHP:DataGrid+Component:+Part+1&ui=blg&ie=utf-8&num=10&output=rssAn Extensive Examination of the PHP:DataGrid Component: Part 1
Material Image, Dennis Pallett examines the PHP:DataGrid component, and has a look at what it exactly is and how to use it in your website. Part 1 of a new DataGrid series! Category:PHP Basics Tutorials Author: PHPit.net ...

lowest price on the crystal shard the icewind dale trilogy part 1 ...
... place you can look for a cheap price is the crystal shard the icewind dale trilogy part 1. be the first to get yours! the crystal shard the icewind dale trilogy part 1. an extensive examination of the php datagrid component part 1.

See The Scarlet Lady Instant Download!See The Scarlet Lady Instant ...
... week of her life on an incredible shopping spree in Paris. Watch The Scarlet Lady online by clicking here! Watch A Preview Of The Scarlet Lady:. Buy MOVIETITLE MACRO Now! An Extensive Examination Of The Php Datagrid Component Part 1.

view emergency squad — get it online instantly!
... negative and bursting with so many extras that it should be against the law. watch emergency squad online by clicking here! watch a preview of :. buy movietitle macro now! an extensive examination of the php datagrid component part 1.

auctions for run run reinder christmas gift basket for babies
run run reinder christmas gift basket for babies. pick the best price & get your run run reinder christmas gift basket for babies today! an extensive examination of the php datagrid component part 1.

fisher price shake ‘n go flyers fighter plane - good prices!
fisher price shake ‘n go flyers fighter plane. pick the best price & get your fisher price shake ‘n go flyers fighter plane today! fisher price shake ‘n go flyers fighter plane. an extensive examination of the php datagrid component part 1.

see the marsh
the dvd includes a behind-the-scenes featurette. — paul gaita. watch the marsh online by clicking here! watch a preview of :. buy movietitle macro now! an extensive examination of the php datagrid component part 1.

download jack reed - one of our own — get it online immediately!
... drugged-out killer and unveil the corrupt politicos who hired him. watch jack reed - one of our own online by clicking here! watch a preview of :. buy movietitle macro now! an extensive examination of the php datagrid component part 1.

watch the paper chase — get it online immediately!
edward herrmann and james naughton co-star in this moving, intelligent drama. watch the paper chase online by clicking here! watch a preview of :. buy movietitle macro now! an extensive examination of the php datagrid component part 1.

best price on wasp wpl606 label printer bw thermal transfer
... thermal transfer on ebay, then check it out on amazon:. and one other place you can look for a cheap price is wasp wpl606 label printer bw thermal transfer. get yours today! an extensive examination of the php datagrid component part 1.

 


 

© 2008 sourceofarticles.com - All Rights Reserved