Brewsterware

March 24, 2008

March Malarky

Filed under: General,Making money — Joe Brewer @ 6:34 pm

Well, at the moment I am recovering from a pretty nasty sickness bug, which wasn’t really the best way to end a relaxing week down in Devon. Most annoyingly, it has also mean’t that I have had to put off a date today. Good job then, that I heard today that I have won a years webhosting package from Derek Semmler in his lastest blog competition. Thanks Derek!

A while ago I blogged about setting targets for 200+ visits a day for this blog by the end of February. Well, unfortunately I have not made that number yet – my closest has been 190 visits when I blogged about making money online. With my networking efforts I hope to smash through the 200 barrier by the end of April.

Here are my most popular blog posts as reported by awstats:

Making money online
Making money online is an extremely popular subject, with forums such as DigitalPoint and SitePoint discussing the top affiliate offers, and Shoemoney and John Chow giving inspiration, it’s no wonder that this is such a hot topic.

Debugging SQL statements for php websites
Not one for really blowing my own trumpet, but what a cool piece of code! I don’t know where I’d be without it now. Try it and see for yourself.

Godaddy coupon codes
With Godaddy continuing to offer discount coupons for their domains and services, check these out and save yourself some money.

Experience with talktalks webmail application
Just recently talktalk have changed their webmail software and added some more load balancing servers and I’m pleased to say that this has made quite a difference.

Happy Easter all!

March 20, 2008

How to debug SQL statements for php websites

Filed under: PHP and MySQL — Joe Brewer @ 6:24 am

About a week ago I asked my friend Simon to help me with what I belived was a particulaly difficult problem with a SQL statement. As it happened, I had made a stupid mistake, and that was that I had used Microsoft Access to help me with building queries. The trouble with Access is that the queries that they produce are not optimised, and they are often over complicated. After a quick SQL tutorial from Simon, I was hungry to practise my new skill, so I decided to rewrite the SQL statements in my Free UK dating site.

It’s been roughly 6 months since I did any significant work on the site, and I knew most of the SQL statements were generated from Access, and a few of them even had some hugely inefficient sub queries thrown in by me. All of the work has been done now, which is why I have been a bit quiet here, and there have been some major improvements – there are now no sub-queries, and many queries have been combined. The main benefit is that many pages that had around 30+ queries and now around 5 queries.

To help me debug some of the queries I wrote the following code that displays the eroneous SQL statement and highlights the part of the statement with the error. This makes it far easier to see where the error is if you have a large query.


function DisplayQuery( $Query, $ExtraText = '' )
{

$search = array(    'FROM',
'WHERE',
'AND',
'JOIN',
'LEFT <br />JOIN',
'ORDER BY' );

$replace = array(    '<br />FROM',
'<br />WHERE',
'<br />AND',
'<br />JOIN',
'<br />LEFT JOIN',
' <br />ORDER BY' );

if ( strlen($ErrorText = @mysql_error()) > 0 )
{

$ErrorNumber = mysql_errno();
$FirstQuotePos = strpos( $ErrorText, "'" );
$LastQuotePos = strpos( $ErrorText, "'", $FirstQuotePos+1 );
$QuerySubString = '';

if ( $FirstQuotePos == $LastQuotePos && false !== $FirstQuotePos && false !== $LastQuotePos )
{
$QuerySubString = substr( $ErrorText, $FirstQuotePos+1, strlen( $ErrorText ) - $FirstQuotePos - 1 );
} elseif ( $ErrorNumber != 1146 && $FirstQuotePos < $LastQuotePos && false !== $FirstQuotePos && false !== $LastQuotePos )
{
$QuerySubString = substr( $ErrorText, $FirstQuotePos+1, $LastQuotePos - $FirstQuotePos - 1 );
} elseif ( $ErrorNumber == 1146 && $FirstQuotePos < $LastQuotePos && false !== $FirstQuotePos && false !== $LastQuotePos )
{
$QuerySubString = substr( $ErrorText, $FirstQuotePos+1, $LastQuotePos - $FirstQuotePos - 1 );
$QuerySubString = substr( $QuerySubString, strpos( $QuerySubString, '.' )+1, strlen( $QuerySubString ) - strpos( $QuerySubString, '.' ) );
}

$Query = str_replace( $QuerySubString, '<span style="background:yellow;">' . $QuerySubString . '</span>', $Query );

}

return '<div style="border: 2px red solid; padding: 4px;">' . str_replace( $search, $replace, $Query ) . $ExtraText . '</div>';

}

Here’s how I use this in my projects:


function exec_sql( $Query, $ShowError = false )
{

if ( !($result = @mysql_query( $Query ) ) )
{
if ( $ShowError )
{
echo DisplayQuery( $Query, '<br /><br />' . mysql_error() );
}
}

return $result;

}

If a query is passed to exec_sql() it will die silently unless the $ShowError parameter is set to true. The error will display with the query and error message, and the erroneous part of the query will be highlited:

SELECT membertable.UserID, MemberName, Sex, Birthday, Orientation, LookingFor, Location, MaritalStatus, Smokes, Drinks, Education, Height, Weight, EyeColor, HairColor, Glasses, photonumber, approved
FROM mem22bertable
LEFT JOIN phototable ON (membertable.UserID = phototable.UserID)
WHERE membertable.UserID=301
AND ((phototable.mainphoto = 1 OR phototable.mainphoto IS NULL)
AND (approved = 1 OR approved IS NULL))

Table ‘brewster_dating.mem22bertable’ doesn’t exist

NOTE: I can’t find a plugin for coloured syntax highlighting at the moment that doesnt display php without any issues – some of the characters above are displayed as html entities. If you want to use the code, click on “PLAIN TEXT”, and the code will be converted into plain text which you can copy and use. If anyone knows of a good coloured syntax highliter for wordpress which works with the visual editor please let me know!

March 12, 2008

Making money online

Filed under: Internet,Making money — Joe Brewer @ 6:06 pm

So, after a week of messing around with OpenX (renamed from OpenAds), and getting excited about learning SQL properly (more about that in a later blog post) I have finally put some ads up. I’ve abandoned the OpenX idea for the time being as it has a more complicated interface than I realised.

My first thoughts on choosing ads was to get as many displayed as possible, but I’ve since realised that it is probably a better idea to choose ads that are more in line with the different niches and products that I actually use myself.

Here are my current advertisers:

Hypnosis Downloads
This company is run by Uncommon Knowledge, a company that specialises in training therapists in the use of hypnosis. I trained with them in 2002 and can honestly say it was a life changing experience. I gained so much confidence and so many amazing friends in the process, plus it has allowed me to help alot of people less fortunate than myself. Hypnosis Downloads has the largest inventory of downloadable hypnosis mp3 files on the net.

GoDaddy
What’s not to say about Godaddy? One of the biggest domain registrars on the net. I’m not sure about their hosting as I’ve never tried it, but as a registrar they are excellent in my experience.

Text Link Ads
I’ve been using Text Link Ads on my blog for quite a while now and think it’s an excellent way to monitize a blog. After installing the ad code on your site, there’s nothing much else to it except letting the dollars flow in!

So there we have it. I’m going to implement OpenX so that I can track the ads better, and try some different advertisers but I’m on my way to making a few more dollars now.

March 2, 2008

New month, new start

Filed under: General,Internet — Joe Brewer @ 6:16 pm

March is marking the beginings of some changes around here. A change of the default wordpress theme has been well overdue, despite the fact that the default theme is pretty hideous, it doesnt do any good to help make new readers stay for a bit. I still need to do a bit of customisation, but I think it’s looking a lot better than it did.

Since my online networking efforts have started to pay off a bit (I’ve have a 20% increase in traffic in the last few weeks), I’ve decided to have a go at making some money on this blog and documenting my progress. Look out for some ads on the right sometime soon.

Powered by WordPress