We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Retrieve data from SQL table? | Forum

Marcus
Marcus May 27 '16
Guys please teach me how to do this?

I create a plugin gust like described on crash course but how do I retrieve or fetch data from other table?

public function getTableName() { return OW_DB_PREFIX . 'contactus_department'; }

But I wanna get the data from other table how to do that please???


dave Leader
dave May 27 '16
well i had it all written out for you buddy, but the dang token got me and erased it all... grrrrr i will retry here in a bit
dave Leader
dave May 27 '16
OK sorry no way i can retype all that :(  


but i dont have to :),  look at the skeleton plugin and look how the BOL folder is set up. 


That is how you get data from your tables. 


To get data from another table you can just put the sql in your bol service file which is the lazy and not so good way (i have learned that over time myself) 


or the proper way, 

at the top of your service file add the BOL call for that other table class and then just return that BOL in your statement. 

The Forum post is edited by dave May 27 '16
Marcus
Marcus May 28 '16
Buddy thanks so much I have just installed "skeleton plugin" and gonna learn this stuff. I know basic PHP but this is for me totally new stuff.
dave Leader
dave May 28 '16
cool, just remember when you want to work with the db, you start your function pointed at the service file, then pass from there to the dao, then pass it backwards


php file function ->  service file -> dao -> return service file -> return php file funciton


all of us including me are guilty of just sticking stuff in the service file and not using the dao as its intented, i learned late how to use the dao and im trying to correct it as i update my stuff.  So basically your sql goes in the dao file.  Now sometimes especially if you are getting data from another table then you can put your sql in the service file and its ok because you dont need to make a dao for another table outside your plugin.  Remember the dao is for each table of your plugin.  So each table has its own dao file.

The Forum post is edited by dave May 28 '16
Marcus
Marcus May 29 '16
Awesome thanks so much again for these pointers really appreciate!