WebsiteDays.com create your web site free, Hosting, Coding, E-commerce, Free Website Builder. Download free website builder to create your website! Personal, and ECommerce website builders...

WebsiteDays.com for italy cagliari

Click on your region below to contact a Websitedays.com designer, or Websitedays.com sales person for info about Online Website builder system.

You can also send an email to

and we can forward your enquiry to respective designers in your area.

Abano Terme Alassio Alba
Albairate Albano Laziale Albenga
Alberobello Albinea Alcamo
Alessandria Alghero Amalfi
Ancona Andorno Micca Anzola dell Emilia
Arbatax Arcugnano Arezzo
Arona Arzignano Asiago
Asolo Assago Assisi
Asti Avezzano Bagheria
Bagno di Romagna Baldissero Canavese Barberino Val d Elsa
Barga Bari Barlassina
Barletta Bassano del Grappa Bastia Umbra
Baveno Belforte del Chienti Bellagio
Bergamo Bettona Biella
Bologna Bolzano Bonefro
Borso del Grappa Botticino Sera Bra
Bracciano Brescia Briatico
Brugnetto di Ripe Bruino Bussero
Busto Arsizio Cagli Cagliari
Calamandrana Calcinelli di Saltara Calendasco
Camaiore Cambiago Camerino
Campo Tures Capena Carasco
Carimate Caronno Pertusella Carpi
Carrara Carre Casasco
Casciano Cascina Cassana
Cassino Castagneto Carducci Castel Maggiore
Castelfidardo Castelfranco di Sopra Castelfranco Emilia
Castelfranco Veneto Castellana Grotte Castellarano
Castellina in Chianti Castello di Godego Castello Roganzuolo
Castelnuovo Berardenga Castelnuovo Rangone Castenedolo
Casterotto Castiglione del Lago Castiglione delle Stiviere
Catania Cattolica Cavaglia
Cefalu Cermenate Cervignano del Friuli
Cesena Chiaramonte Gulfi Chiavenna
Chiusi Cicagna Citta di Castello
Cittadella Civitavecchia Codognč
Cogne Colle di Val d Elsa Colorno
Como Conegliano Conversano
Corciano Coriano Cormano
Corropoli Corsico Cortina d Ampezzo
Cortona Cosenza Courmayeur
Cremona Crosio della Valle Cuneo
Cusano Milanino Dalmine Deruta
Desenzano del Garda Diano Marina Dogliani
Doglio Donnini Empoli
Erba Ercolano Fano
Ferrara Fiesole Fiorano Modenese
Florence Follonica Forlė
Formigine Forte dei Marmi Francaville a Mare
Frascarolo Frosinone Fumane
Gaggio Montano Gallarate Gambettola
Garda Gardone Riviera Gardone Val Trompia
Garessio Gargnano sul Garda Gemona del Friuli
Genoa Genola Genzano di Roma
Gerace Grado Greve
Grosseto Grottammare Gubbio
Igea Marina Imola Imperia
Ispra Varese L Aquila La Spezia
Lainate Lampedusa Lana
Lavezzola Lecco Licciana Nardi
Licenza Lido di Jesolo Livigno
Livorno Loano Lonato
Loria Lucca Lugo
Lurate Caccivio Madonna di Campiglio Magenta
Malcesine Malo Maniago
Mantua Manzano Marebbe
Marina di Massa Marostica Marradi
Martellago Masiano Massa
Massa Lubrense Mathi Meleto Valdarno
Menaggio Merano Merate
Messina Mestre Milan
Minerbio Minturno Misano Adriatico
Modena Molinella Molvena
Monfalcone Monsummano Terme Montaione
Montalcino Monte Sant Angelo Montecatini Terme
Montegrotto Terme Montelabbate Montepulciano
Monteriggioni Monterosso Almo Montesilvano
Montespertoli Montevarchi Montichiari
Montieri Monza Motta di Livenza
Muggia Mulinetti di Recco Murano
Musile di Piave Naples Naz-Sciaves
Neive Nichelino Nogaredo
Noicattaro Novafeltria Novara
Nuoro Ontagnano di Gonars Ortona
Osimo Ostia Otranto
Ottobiano Padua Paina di Giussano
Palaia Palermo Palestrina
Palinuro Pantelleria Parma
Parrano Passignano sul Trasimeno Pastine
Pavia Pavona di Albano Pederobba
Pergola Perugia Pesaro
Pescara Peschiera Borromeo Pescia
Piacenza Pienza Pietrasanta
Pinerolo Piove di Sacco Pisa
Pistoia Pitigliano Poggio dei Pini
Polvica di Nola Pomezia Pompei
Ponsacco Pont Canavese Pontassieve
Ponte San Pietro Pontedera Poppi
Porcia Pordenone Port Ercole
Portico di Romagna Porto Recanati Portofino
Portogruaro Positano Praiano
Prato Provaglio d Iseo Punta Ala
Quart Quartu Santa Elena Radda in Chianti
Ragusa Ravenna Recanati
Reggio Calabria Reggio Emilia Rezzato
Rho Riccione Rignano sull Arno
Rimini Riva del Garda Rivarolo Canavese
Rivoli Rome Rovereto
Rovigo Rozzano Sabaudia
Sala Baganza Salerno Salt di Povoletto
San Gimignano San Giorgio di Nogaro San Giovanni Rotondo
San Giovanni Valdarno San Giuliano San Michele all Adige
San Miniato San Pancrazio San Pietro di Feletto
San Remo San Vendemiano Santarcangelo di Romagna
Sarcedo Sarezzo Saronno
Sarteano Sassuolo Savogna d Isonzo
Savona Scandicci Scarperia
Schio Sedilo Selva di Val Gardena
Senigallia Sestriere Settimo Torinese
Siena Silvi Sirmione
Sondrio Sorrento Spello
Spezzano Spoleto Stresa
Subbiano Suvereto Taormina
Tarano Taranto Tavarnelle Val di Pesa
Termoli Terrasini Thiene
Todi Tolentino Torrebel Vicino
Tortoreto Tradate Treiso
Trento Trevignano Treviso
Tricesimo Trieste Triuggio
Tuoro sul Trasimeno Turin Udine
Urbania Urbino Valdagno
Valeggio sul Mincio Valenza Valverde
Varallo Varenna Varese
Vasto Vatican City Venice
Vercelli Verona Viagrande
Viareggio Vicenza Vieste del Gargano
Vietri sul Mare Vigano Vigevano
Villa a Sesta Villa del Conte Villanova d Asti
Vimercate Vinci Vipiteno
Viterbo

»   An Extensive Examination of the PHP:DataGrid Compo

Article submitted in category: Web Design And Development
Tags: | datagrid | phpdatagrid | => | data | code | component | array | $data | database | use | it's | table |

An Extensive Examination of the PHP:DataGrid Component: Part 1 by: 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 (http://phpscripts.pallettgroup.com/phpdatagrid/?ref=phpit) 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 (http://phpscripts.pallettgroup.com/?ref=phpscripts), 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 (http://www.php.net/variables.predefined), 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>&laquo; Return to the article</strong></a>

</body>

</html>[ View live demo (http://www.phpit.net/demo/datagrid%20examination/datagrid1.php) >

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 (http://phpscripts.pallettgroup.com/phpdatagrid/?ref=phpit)

Don't forget - use coupon code phpit for a 10% discount!

About The Author

Dennis Pallett is a young web developer, currently still studying. He owns several websites, including PHPit (http://www.phpit.net) and WebDev-Articles (http://www.webdev-articles.com). If you would like to reach him, you can contact him at writing@nocertainty.com

dennis@nocertainty.com

This article was posted on August 15, 2005