RSS
 

Archive for July, 2009

Creating XML in PHP

28 Jul

Quite often I need to create some XML via PHP, pulling data from a MySQL database.

I have tried various methods but I always come back to this. I like the way that I get full control over doing it explicitly, so thought I would share the code. I am using the MySQL PHP class from Ricocheting.

There are loads of examples out there already on the web, but I hope the code below is very easy to understand as it uses simple PHP code.

<?php
 
//pick up required variables
$userName = $_GET['username'];
$password = $_GET['password'];
 
//include the required files
require_once('config.php');
require_once("Database.class.php");
 
// create the $db ojbect
$db = new Database($config['server'], 
	$config['user'], 
	$config['pass'], 
	$config['database'], 
	$config['tablePrefix']);
 
// connect to the server
$db->connect();
 
//build the query
$query = "SELECT * FROM ".$db->pre."useraccount "; 
 
//build the where statements
$where = "WHERE (userAccountId > 0)";
 
if ($userName) {
	$where = " AND (userName = '" . $db->escape($userName). "')";
}
 
if ($password) {
	$where = " AND (password = '" . $db->escape($password). "')";
}
 
//get the FULL record count
$sql2 = "SELECT count(0) AS theCount FROM ".$db->pre."useraccount $where";
 
$countRecRows = $db->query($sql2);
while ($countRecRow = $db->fetch_array($countRecRows)) {
	$recordCount = $countRecRow['theCount'];
}
 
//execute the main query
$countRows = $db->query($query . $where);
 
//set up the php headers so that the page doesnt cache etc
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/xml");
 
//include the page header info
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
 
//begin the xml data
echo "<useraccounts>\n";
 
//set up the result info
echo  "<total>$recordCount</total>\n";
 
//loop through all the records
while ($row = $db->fetch_array($countRows)) { 
	echo "<useraccount id=\"".$row['userAccountId'] ."\">\n";
 
	echo "<username>";
	echo $row['userName'];
	echo "</username>\n";
 
	echo "<fullname>";
	echo $row['fullName'];
	echo "</fullname>\n";
 
	echo "<accesscode><![CDATA[";
	echo $row['accessCode'];
	echo "]]></accesscode>\n";
 
	echo "</useraccount>\n";
}
 
echo "</useraccounts>";
 
//free the result
$db->close();
?>
 
 

XML Output From PHP

28 Jul

Just a quick one. If you want to output XML from your PHP page you need to set the Headers correctly.

Here is the code you need to include, and it has to be before anything else is printed.

<?php
   header ("Content-Type:text/xml");
?>
 
 

Google Voice. One number. Free. Forever?

28 Jul

googlevoice

Google have launched a new service called “Google Voice” which is basically an application for your PC or your mobile which works via the internet connection, that then behaves like a telephone.

They supply you with a new phone number, for free, and then you add all of your own phone numbers to it. If someone calls your Google phone number – all of your phones will ring. This means that you will only ever need to give out that one number ever again! This is very useful, especially if you work internationally, as a freelancer or change mobiles often.

The service is only available at the moment go Google GrandCentral users, but should be launching soon to the general public.

The only reason I even heard about this service is that Apple have now blocked the sale of the Google Voice application from their iPhone’s App store, claiming the reason: “it duplicates functionality available with the iPhone” – which surely translates as: “Our partners such as O2 and AT&T will be forced to do something about their prices and they really dont like it“…

Google Voice is a service that gives you one number for all your phones, voicemail that is easy as email, and many enhanced calling features like call blocking and screening, voicemail transcripts, call conferencing, international calls, and more.

Google Voice is currently available for GrandCentral users only, but will be open to new users soon. In the meantime, please leave us your email address and we’ll notify you as soon as Google Voice becomes available. To learn more about Google Voice, check out our feature videos.

Im sure there are probably a few problems with the software at the moment, but knowing Google they will work at it until they have an unrivaled service, just like with their Search tool and Apps. Not sure how they will pay for this, but I heard a roumor that they may eventually play adds during calls?

I’m looking forward to trying it out.

 
 

Writing a component for Joomla!

27 Jul

joomla_logo_horz_color_sloganToday, I have written my first component for the Jooma! CRM system.

Following the tutorials on the developer.joomla.org website was actually very straight forward and I have been able to create a simple component of my own. I will be working on this over the next few days / weeks and will release it to the open source community when its done.

For those who haven’t heard of Joomla!, it is a template based web content management system. Once you get the hang of things you can use it to create entire websites in no time at all. It comes with loads of built in functionality and best of all, you dont need to know how to do any programming. Its almost as easy to create a web page as it is to type an email.

 

Installing Aptana on Ubuntu Linux 9.04

26 Jul
aptana

Aptana Studio IDE

UPDATE: With the latest version of Aptana 2 and Ubuntu 9.10 it seems you dont need to do this hack anymore. Try it without first of all, then if you get problems – apply the fixes as described.

I have been using the Aptana IDE for PHP and Ajax development for a while now on my Windows system, and have decided that it is much better than the standard Eclipse, at least for me. I wanted to start using it on my Linux machine but encountered problems which prevented it from running.

It took me a while to find out how to get it to work, but thanks to Google and some others who have had this problem before me, I now have a working Aptana Studio on my Ubuntu system.

Here is how to get it working:

  1. Download and extract Aptana Studio for Linux (All in one) from here.
  2. Use Synaptic to install xulrunner (version 1.8).
  3. Use Synaptic to install a JRE.
  4. Create a text file (in your home folder etc) which we will use to set up the Aptana environment and execute the application. Call it startAptana.
  5. Paste the text from below in to the new text file, and be sure to change the bottom line so that it matches the path to your Aptana installation.
  6. Make the startAptana file executable.
  7. Double click the startAptana file to start using Aptana, or create menu icon that links to it.
#!/bin/sh
MOZILLA_FIVE_HOME=/usr/lib/xulrunner
if [ $LD_LIBRARY_PATH ]; then
   LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME:$LD_LIBRARY_PATH
else
   LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME
fi
export MOZILLA_FIVE_HOME LD_LIBRARY_PATH
/home/sam/Apps/aptana/AptanaStudio
 

Notepad2 – Text Editor, replacement for Notepad

15 Jul

NotepadI have recently started using Notepad2 again.

Its a really fast, small, simple text editor -  just like Notepad but with a few added features – such as syntax highlighting. Very useful for editing SQL files, PHP scripts and so on.

http://www.flos-freeware.ch/notepad2.html

 

True Stories: Taking Liberties (More4)

15 Jul
A Police State?

A Police State?

I watched a fascinating documentary last night about how our liberties are being taken away, primarily as a response to the threat we face ‘from terrorists’. New Labour seem to be the culprits and since 1997 when they came to power, many of our most important rights have now been taken away from us – including our right to protest, right to trial by jury, detention without charge… and the list goes on.

Boris Johnson manages to come across as sensible for once, when he advises the Government on identity cards: “Just butt out of it.”

http://www.channel4.com/programmes/taking-liberties

Here is what the producers of the programme have to say about it:

Riding in on a wave of optimism and real belief in their mantra that things can only get better, the New Labour government proceeded to enact some of the most authoritarian legislation in recent history. With fast-paced satirical style, this Bafta-nominated film shows how, in just over a decade, some rights and freedoms that took centuries to build up have been rolled back or cut away through a personal journey into the decline of civil liberties.

The 82-year-old holocaust survivor Walter Wolfgang was lifted bodily from a debate at the Labour Party conference for, as Tony Benn points out, ‘rightfully’ saying that Jack Straw is talking ‘nonsense’ about Iraq. We see a man who tries to protest against the treatment of Mr Wolfgang also set upon by security, and learn that he was later handled roughly – and that poor old Wolfgang was next detained by the police under the 2000 Terrorism Act.

We meet Moulad Sihali, an Algerian refugee. He was cleared of all charges relating to a non-existent plot to manufacture the poison ricin, but has now been made a prisoner in his own home. He’s been fitted with a tracking device, is only allowed outside at certain hours – and then only within a one mile radius of his house – and is forbidden to meet anyone who hasn’t been vetted by the Home Office. The specific charge against him? There isn’t one. Read the rest of this entry »

 
 

Garage Band

14 Jul

Even though I have used Ableton in the past and have created a few tracks with it, I have decided to start off using the GarageBand software which comes with OSX . I know Ableton has all the bells and whistles anyone could want, but I’m not sure I need something so involved at this stage.

garagebandMaybe once I feel I have reached my creative limit with GarageBand I will move back up to Ableton, but this time around, seeing as I haven’t even managed to record anything I like the sound of yet, that is definitely a long way off.

GarageBand comes with loads of sounds, seems simple to use and works with the USB XioSynth without any problems.

Currently, the Mac is downloading updates and sound-banks for OSX and GarageBand which total over 1.3GB, so its going to be going for a while.

 
 

jQuery to toggle read only property

14 Jul

Today I needed to make a change to our web-based software that would allow input to a field, if a specific category was set, and stop entry otherwise.

This is the jQuery that I used to do the job.

if (category == 'Title') {
$('#quoteDetailDescription').removeAttr('readonly');
} else {
$('#quoteDetailDescription').attr('readonly', true);
}
 

Bubble popping photos in super slow-motion

14 Jul
One of the images by Richard Heeks, from Exeter

One of the images by Richard Heeks, from Exeter

I would never normally link to anything on the Daily Mail website, but this was just amazing. Photographer Richard Heeks has managed to capture some images of a bubble being burst in super slow-motion and amazing detail.

Read the full story and see more images here.