salmander Posted June 26, 2011 Share Posted June 26, 2011 Hi, I am new to php OOP. I have developed few projects using procedural php. I am converting my already existing php (procedural) project to php oop. As its a very small and basic project. So I thought that it would be a good practise for me to deal with the problems before actually touching big projects. Ok, so I have one database and one table in that database. I am making one class (class A) to connect to the database and fetch the data. And I want a separate class (class B) to format that data in a table form. Then class B will be called in the index.php page to display it. I know I am not very good at explaining things....but I hope I have made my point clear. its a simple task but I need some experience programmers help to tell me what approach shall I take? Right now I can successfully able to to fetch one field from the database and return it. Thus when I call this function in other class (class B) its displaying it. In procedural php i used a while loop to fetch all the fields from the database and echo it. It was easier as the data is not travelling from one function or class to another class. Now I dont understand how to I fetch all the fields from the database and then pass it to another function or class. Hope you understand what I am trying to say. Ask me if you need to clarify anything. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/240474-fetching-data-from-database-using-php-classes-oop/ Share on other sites More sharing options...
ignace Posted June 27, 2011 Share Posted June 27, 2011 Take a look at the available PEAR packages. They already have classes that will create an HTML table from a database result. If you want to start from scratch, you can take a look at how they did it or try to combine some of the packages (like HTML_Table) with already existing built-in functionality like PDO. Quote Link to comment https://forums.phpfreaks.com/topic/240474-fetching-data-from-database-using-php-classes-oop/#findComment-1235318 Share on other sites More sharing options...
salmander Posted June 27, 2011 Author Share Posted June 27, 2011 sorry but i dont understand anything you said....lol Sorry I dont have much experience with object oriented. can you tell me in a bit more detail please? Quote Link to comment https://forums.phpfreaks.com/topic/240474-fetching-data-from-database-using-php-classes-oop/#findComment-1235636 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.