the life and times of a failed jedi...

- Saturday, May 31, 2008 -

tentative foray into php coding advice

If you're not interested in PHP coding please stop reading.

I'm open to correction on this, but I thought I'd put it out there in case it's helpful to anyone OR in case someone can point me to a simpler solution.

I've been developing the simple content management that powers the strangeday site news and gigs. The key points here are:
- I was using object oriented programming
- I used the PDO (PHP Data Objects) class for the database connections etc.

When it came to uploading, I quickly realised that my hosting provider, A Small Orange, has PDO disabled. So far so bad. However since I'd separated out what I was doing with the Object Oriented approach it was simply a matter of changing the database connection class and everything else would be hunky-dory.

Not so much.

My actual page was using the PDO Statement which gets returned as an array. Here's the final output code:


<?php
$i = 1;
foreach ($results as $newsitem)
{
?>
<p class='line<?=$i?>'><span class='newsitem'>..</span><?=$newsitem['title']?></p>
<?php
$i++;
}
?>


And here's the PDO code that was returning the query:


try
{
if ($squery = $this->dbh->query($query)) return $squery;
}
catch (PDOException $e)
{
die ("Database error @select: " . $e->getMessage() . "<br />\n");
}


My troubles began when I stopped using PDO::Query and changed to using mysql_query and mysql_fetch_assoc so that it would work on A Small Orange.

I ended up with an error in the foreach. What I wanted to do was change the connection side of things so that I could switch it depending on whether the hosting environment supported PDO or not.

What I needed to do was output an array that was functionally the same as the PDO Statement array. Here's what I came up with:


$result = mysql_query($query);
$squery = array();
while ($row = mysql_fetch_assoc($result))
{
$keys = array();
$values = array();
foreach ($row as $key=>$value)
{
$keys[]=$key;
$values[]=$value;
}
$squery[] = array_combine($keys, $values);
}
return $squery;


Obviously this needs error handling and I also wrote functionality into the class that would switch based on a PDO = true or false flag type arrangement but that's essentially my solution.

Comments/suggestions?

Labels: , , ,

- Monday, April 28, 2008 -

making the webs look better

I hope.

I pimped up the Misses' blog.

Yeah. I think it looks nicer. She designed it, but I changed that design into HTML/CSS so it looked nice. Then I put it into the blogger template and hacked that all to pieces so it looked the same as the nice one. Nice.

In other news. Studio.

over

Labels:

- Tuesday, November 06, 2007 -

fisheye

Ideas that I can't quite get to work properly.

Very much my style I'm afraid.

I've seen A LOT of blogs about html/css tricks/hacks/etc. Kind of comes with the territory of being a web designer with no formal training. Or maybe the territory of being a web designer (I hope). Any case, I really ought to take some notes of how I manage to fix things and pass it on. But I haven't so far. Kind of seems like a lot of work. I guess I should pass on the knowledge though.

We'll see.

I'm really tired and it's not even 9 of the clock. That is lame. And also lame.

overandout

Labels: ,

- Tuesday, October 23, 2007 -

web dizzy(ne)

Oh gosh.

Web design is one of the most infuriating things I have chanced my hand at. You think you've got something nailed but then you look at it in a different browser and BAM! Added to that I was trying to edit a Flash 8 file using Flash CS3 which was mostly fine but there were one or two things that just weren't as they should have been. Something which I can only guess at attributing to the discrepancy between the two versions..

Still. I think I'm done now. Until I get another raft of changes that is, I suppose.

Anyways.

Half-term is lovely thanks. Got band practice tomorrow, something else on Thursday, the usual on Friday and ohmygod David Ford at Shepherd's Bush Empire on Saturday. Hella.

I suspect it's all going to be over far too soon.

But I will enjoy it!

overout

Labels: , , , ,