Zend Certified Engineer

phpguru.org

Free PHP, Javascript and C# code

Datagrid and arrays (again)


Programming , PHP , Computing , MySQL
14th May 2008, 21 views

[Direct URL for this article]

So I got bored and I've just added array support to the Datagrid class. You can see it in action by looking at example9.php. Instead of supplying the connection parameters and the SQL query to the static Create() method, you simply supply the array. The array should be two dimensional, like that returned by mysql_fetch_assoc(). Indexed first numerically, and then by "column name". Barring any problems, this will be "released" shortly.
0 Comments...

Datagrid and arrays


Programming , PHP , Computing , MySQL
13th May 2008, 180 views

[Direct URL for this article]

I put it to you... should the datagrid support arrays as the data source as well as MySQL result sets? I'm thinking maybe it should, mainly because I need something to do. :-/ But I can see the situation where you might want to test and setup the datagrid by just giving it an array, before you actually set it up correctly for MySQL. Or maybe there's connection issues and you want to make sure that the datagrid isn't the problem. But regardless, should the datagrid support arrays?
7 Comments...

A cute search box


PHP , Web
11th May 2008, 373 views

[Direct URL for this article]

That's it really. A cute search box that's "self contained" inside a PHP function so it's extremely convenient to display. What can I say? I got bored... [Link]
25 Comments...

UK hosting costs


Web , Computing
10th May 2008, 74 views

[Direct URL for this article]

Just looked at Demons hosting offerings, and to be honest, I was shocked. Compare this with a whole server (not virtual, or at least not touted to be) which you can get from 1and1. More disk space, more bandwidth (granted their service is awful) - why on earth would anyone choose Demon at these prices? If it's service you're after then you really should choose someone like Rackspace (if you can afford it). Failing that, my advice is to choose anyone but Demon and save yourself (a lot) of money! All in my opinion of course...
1 Comments...

Displaying errors


Programming , PHP , Computing
7th May 2008, 288 views

[Direct URL for this article]

In reply to this, here's a technique for controlling your error reporting:

<?php
    $isDev  
= $_SERVER['SERVER_NAME'] == 'dev.phpguru.org';
    
$isLive = $_SERVER['SERVER_NAME'] == 'www.phpguru.org';

    if (
$isDev) {
        
error_reporting(E_ALL);
        
ini_set('display_errors', 1);

    } elseif (
$isLive) {
        
error_reporting(0);
        
ini_set('display_errors', 0);
    }
?>

You don't have to create the $isDev/$isLive variables, but if you do you can reuse them elsewhere. I suppose you could if you wanted to use the Registry pattern I highlighted here some time ago, eg Config::$isDev

You could even use this technique to hide content on your live server that's not quite ready to go live yet.
25 Comments...

Datagrid update


Programming , PHP , Web , Computing , MySQL
6th May 2008, 187 views

[Direct URL for this article]

Just "released" the latest version of the Datagrid. Updates include:

  • You can disable sorting for a given column or columns.
  • Paging now has a "paging" CSS class (the next/prev links only). The bit that tells you how many rows there (x of y results) has the "paging_results" CSS class
  • Order by links now preserve existing GET variables - thanks Tom
  • Fixed hard coded perPage - thanks David
  • Added NoSort() method which, unsurprisingly, disables sorting for a given column (or columns).
[Link]
0 Comments...

Web based chat


Programming , PHP , Computing , MySQL
3rd May 2008, 257 views

[Direct URL for this article]

After an email (or two) on the php-general list, (of which I only read the subject), I've created a multi user web based chat system. Here.

Oh the fun. The status bar is irritating though - in that it keeps flashing as it downloads the page (maybe this could be fixed by the use of toilet cleaner, I mean AJAX). Oh and like IRC it will track the converstaion from the time you enter the chat room. And because it refreshes every second, the load average on the server will not be thankful.
3 Comments...

[Article index]