I created a page (using many tutorials and with some help from nice users on this site, Big thanks to all who is sharing experience) with loginfunctions and a forum and a reporting system.
The page consist of a leftside div used as menu and a main div - thepage that is updated depending on menuchoice.. I also have som forms for gathering user input that is stored in the database.
For the leftside div I have some stuff like top ten users which is basically a div with a bg picture and in that div i have a small user specific picture, I echo (using css+divs) the username, user rating, joindate and so on. All the code for this is inside the main.php and it feels ugly to me (it works fine but I want to become better at OOP and become a better programmer). So now finally to my question...
"Is it possible to make a class or function that i call with the variables that can return the whole package to my mainsite.. I dont know how to explain it but I will try some pseudocode below".
Code: Select all
db call here (Sort by userratind DESC 0,10)
while != end of table {
CreateThisCoolDivAndSendItToMainPage($link_to_background_to_use_in_the_divelement, $username, $userrating, $linktouserpic, $and_so_on...);
}
// Now I want the entire div (say height:50px width:200px) with everything filled out and CSS formatted back so I just put the entire div element into my leftside div column on the page.
This to me feels like the divelement would be like a schoolbook example for when to use a class like I could have a class menuitem where i define functions like set_height, set_width, set_background and then i can derive class users extend menuitem with functions like set username, set userrating and so on.
So I already have this functionality on my site today, I just want to learn more about OOP but I dont know how to do to return a div package with backgroundpicture and subdivs with text.. Actually now when im thinking about it I guess I could do it as a function that returns an image where the function will create the image from a backgroundimage and a user image and some text where the function is positioning the text... Well anyway that is almost what I want... a function/class where i put in alot of stuff and recieves back an img formatted in a special way. (But I would prefer if possible to receive it as a div with text so I can for example make the username clickable to redirect to the users homepage or whatever...and NO I dont solve that by making the image clickable since clicking the entire div will redirect you to another page)..
Err sorry I hope You understand what I'm trying to do.. I got carried away writing this so I'm not sure I understand myself from what I just wrote haha..
Thanks a bunch in advance