I’ve work with basic PHP for some time, and there is something I cannot quite figure out.
Let’s say I’ve a database with several real estates, each real estate has its attributes like the ID, price, number of rooms etc etc etc, this info is in one table only. I have in other table (same db) let’s say, the map locations for each real estate per ID.
How can I create a script, so that everytime I need to access a real estate full info (different tables) I dont have to make all the queries again, and do something like this:
echo realestate->id;
echo realestate->name;
echo realestate->price;
also when I call for ex. realestate->id; how do the script knows witch realestate to fetch?
Thank you for your help!
This is too broad a question. Best thing you can do is read these articles:
The short and quick version is that you create a class, within it you define properties that it has, such as variables and/or other objects. Then you can write a function that goes off and gets data from the database (this could be part of a special function called a constructor which gets invoked whenever you create the object). You can create other functions that do all sorts of stuff to the data, such as outputting to a webpage or updating new information and so on.
The more detailed version is in these:
http://php.net/manual/en/language.oop5.php
Probably start here:
http://www.php.net/manual/en/language.oop5.basic.php