Different data views from the same block data

Permalink
Hi,
I just need a pointer here. I have the guestbook add in on a site. This all works ok.
What I want to do is pull a random record from the base table and display it in another part of the site.

I know I can easily do this just in php by selecting a random record from btGuestBookEntries table and rendering it to the screen but is there a proper/better way to do this within Concrete5?

Any pointers would be extremely useful. I want to learn how the system works as much as possible rather than just resorting back to straight PHP as soon as I can't work something out. Still trying to get my head around some of the basic concepts.

thanks,

Andy

 
ijessup replied on at Permalink Best Answer Reply
ijessup
As far as I am aware, just snagging the data straight from the DB would be the best approach.

And easiest... something like:
$db = Loader::db();
$db->Execute('SELECT * FROM btGuestBookEntries ORDER BY rand() LIMIT 1');
EDIT: Above not tested, but you should get the idea.
WebcentricLtd replied on at Permalink Reply
thanks for that. Is very late here and I was overcomplicating things - was trying to figure out how I could add a version of a block just showing the 2 fields I wanted from the data of another.

Had totally forgotten I can put the code in the page rather than insert it as a block.

Just need to add some code to check the page id so the comment only shows exactly when I want and I'm sorted.