News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Zend Developer Zone:
Fetching multiple random rows from a database
May 06, 2009 @ 11:17:03

On the Zend Developer Zone, a recently posted tutorial looks at fetching multiple random rows from a database table (in a MySQL database).

As a follow up to my earlier article about fetching a single random row from MySQL I will tell you today, how you can fetch multiple random rows from a table without any hassle. Compared to the solution with fetching a single random row, fetching multiple random rows requires some tricks.

The tutorial walks you through the creation of some sample tables, making a simple trigger to keep a "random ID" column in a value range of one to the number of rows (gapless) and a bit of PHP code to select some IDs from the table and the SQL to get their information.

Be sure to check out the comments for mentions of the number of table reads and how optimized certain parts of the queries might be.

0 comments voice your opinion now!
mysql random gapless trigger row multiple database


Jani Hartikainen's Blog:
Closures coming in PHP 5.3 and that's a Good Thing
February 20, 2009 @ 14:05:56

Jani Hartikainen takes a look at closures in a new post to his blog - why their good and why they can help you more than you know.

PHP 5.3 will be introducing closures to PHP. Closures, also known as anonymous functions, will allow you to declare functions "inline" and store them in variables. While the syntax may seem a bit weird compared to how it is in languages like JavaScript, closures will be a useful addition to the language. However, like reflection, it's a feature that may not immediately show it's usefulness...

He explains what they are (a sort of anonymous function) and a simple example of them in use - a function that works with data from an array to display each of the rows with the given "formatter" function. Another brief example is a method of using them in PHP functions like array_map and usort as an argument for the callback parameter.

0 comments voice your opinion now!
closure php5 good anonymous function example row loop callback


Lorna Mitchell's Blog:
Introduction to Zend_Db
October 31, 2008 @ 12:57:07

Lorna Mitchell has an introduction to Zend_Db, the Zend Framework database abstraction layer posted to her blog today:

I recently worked on a project which was based on Zend Framework - I haven't worked with it before and I was temporarily confused by the existing implementation of some of the database-level stuff. After much reading and untangling of code, I'm now pretty clear how this should look, so here's my overview. I'm not going to go into setting up a whole application, but this is a quick primer on how data models go together.

She talks about table modeling, fetching rows/data from the model and working with rows/rowsets.

0 comments voice your opinion now!
introduction zenddb database zendframework fetch row rowset


Jani Hartikainen's Blog:
Understanding Doctrine's NestedSet feature
September 02, 2008 @ 10:29:56

On his CodeUtopia blog Jani Hartikainen gives an inside look at a feature of Doctrine, nested sets.

The Doctrine library comes with a feature called nested set, which makes saving trees in a database easy. However, it's quite easy to accidentally cause a lot of extra unneeded queries if not being careful. Here are some pointers to keep in mind while working with the nested set, and some example queries to make understanding it easier.

He gives an example, showing how to get rows from the database - parent and child - and some optimization tips to keep things light. There's also some pros and cons included for doing it either way (the standard fetching or using the more optimized versions).

2 comments voice your opinion now!
doctrine nestedset feature fetch database row parent child


DevShed:
Using Timers to Benchmark PHP Applications
April 30, 2008 @ 14:31:08

DevShed has posted the second article in their series looking at benchmarking your PHP scripts. This time they look at the use of "timers" to check on script execution length.

Since you already know how to create timer functions and classes, in this tutorial, I'll create some concrete examples that show where these timing mechanisms can be applied in order to evaluate the performance of certain PHP applications.

They create a few classes that connect to a database and pull out rows (handing it off to a Result class). They use these classes in two examples - one with compression (output buffering) and one without using their Timer class to evaluate the differences.

0 comments voice your opinion now!
timer benchmark application tutorial class mysql row output buffering


WebReference.com:
How To Create Alternating Row Colors in PHP
June 20, 2007 @ 11:12:00

WebReference.com has a simple new tutorial today showing how to create alternating table rows in the output for your application.

Almost every database driven Web site uses alternating row colors when displaying a list of records, a concept used all over the Internet. You've seen it used, you like it, and now you want to do it yourself. But you're not sure how to accomplish it. Well you've come to the right place. I'm going to discuss the basic idea behind achieving this and give some concrete examples demonstrating different ways to implement it.

Their script loops through the information (numbers in their case) and checks, using the modulus operator to check and see which of the CSS styles it should apply to the div. To give a range of possibility, they also show how to do it with a while loop instead of a for to do a little benchmarking of the methods.

1 comment voice your opinion now!
alternate row color table forloop whileloop css alternate row color table forloop whileloop css


MSBWare.com:
Alternating Row Colors
May 02, 2007 @ 16:13:00

Sometimes, a simple approach is the best. That's what Michael Berman went with in this light and easy tutorial. It focuses on the creation of an "alternating rows" script with PHP.

This concept is used all over the internet. Almost every database driven website uses alternating row colors when displaying a list of records. You've seen it used, you like it, and now you want to do it yourself. But, you're not sure how to accomplish it. Well you've come to the right place. I'm going to discuss the basic idea behind achieving this and give some concrete examples demonstrating different ways to implement it.

The example code show how to alternate between two colors - white and grey - for the background of a series of DIVs. He even includes a series of tests to show which method of switching them out would be faster (while loop, for loop, etc).

0 comments voice your opinion now!
alternate row color loop benchmark tutorial alternate row color loop benchmark tutorial


DevShed:
Using Unbuffered Queries and More with SQLite with PHP 5
December 11, 2006 @ 12:46:00

Continuing with their look at PHP5 and SQLite, DevShed has posted part two of the series - "Using Unbuffered Queries and More with SQLite with PHP 5".

Taking into account the group of characteristics that I mentioned [a few lines above], in this second tutorial of the series, I'll be taking a look at some of them. This will give you a clearer idea of how to use them as part of your existing and -- why not? -- future PHP applications.

They take a look at the hows and whys of working with the unbuffered queries and well as some examples - counting rows and fields in a database table and looking at the use of more "row-processing methods" to get different sorts of data out.

0 comments voice your opinion now!
unbuffer query sqlite part2 php5 row field processing unbuffer query sqlite part2 php5 row field processing


DevShed:
Introduction to Using SQLite with PHP 5
December 04, 2006 @ 13:59:32

DevShed has started a small series today that seeks to guide you through the world of SQLite as is interfaced through PHP5.

If you use PHP 5 to build web-based applications that access a database, you might want to consider SQLite. A "lighter" option than MySQL, this database may still suit your purposes if you don't need all of MySQL's bells and whistles. This three-part series covers many of SQLite's most useful features.

Their post today, part one talks about the basics of the protocol and how to get started with it in PHP5. Since it's enabled by default, the chances of it being on your installation are great. They only really look at grabbing data from the database in this part, saving pushing data back in for another time.

0 comments voice your opinion now!
sqlite php5 database fetch tutorial basics row sqlite php5 database fetch tutorial basics row



Community Events





Don't see your event here?
Let us know!


symfony release introduction version laravel interview voicesoftheelephpant podcast library package series install composer tool language framework security opinion update community

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework