Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - tomelders

Pages: [1]
1
Code Snippets /
« on: March 09, 2007, 11:24:51 AM »
thanks for the pointer, I knew there must have been a better way of doing that. I'll update it over the weekend hopefully and post again on monday.

-t

2
Code Snippets / Lazy Object
« on: March 09, 2007, 09:08:21 AM »
This may be useful for anyone working with MySQL tables (which I imagine includes everyone) who would like to take an object orientated approach to the development.

http://www.tomelders.com/resource/LazyObject.php.zip

This object will take a mysql select query and create an object out of it. so say you have a user table...
Code: [Select]
$my_user = new LazyObject("SELECT * FROM my_user_table WHERE ID=$id");

obviously the SQL depends on your table set up, but all your field values are now available like this

Code: [Select]
echo("<p>" . $my_object->user_login);
echo("<p>" . $my_object->user_email);
// etc etc

You can also set your object properties like this...
Code: [Select]
$my_object->user_login = "Spartacus";

Lazy Object will take care of updating your MySQL table for you automagically.

also, if you don't include a WHERE clause in your query, or your query returns more than one row you can use the next() method,

Code: [Select]
while($my_object->next()):
   echo("<p>" . $my_object->user_login);
endwhile;


There are also a bunch of other methods in there but right now I need to clean it up a little. I also doubt that I'm the first person to do this and I doubt it's the smoothest execution possible, but I'm finding it useful, I hope someone here does too. It's open source and all that so feel to share and make better.

Peace Out
-t

3
Greetings / Hello, again
« on: February 28, 2007, 11:37:23 AM »
Here's my post so I don't get deleted. Hello to everyone. it's been a number of years since I've been here. Hopefully I'll be able to contribute some answers this time. I think I'll head straight over to the beginners section!

-t

Pages: [1]