php - Is it best to make fewer calls to the database and output the results in an array? -
I'm trying to make a more concise way to call hundreds of DB calls. Every time I wanted to output a field, instead of typing the whole query, I tried to close that code in a class that used to work all the queries. This is the category so far:
Information is easy to access.
$ listing = new listing; counterpart $ listing-> getListingInfo ('', 'books') -> title;
This first category in the "Books" category But if I want to produce the price of that listing, I will have to make another call to get the listing (). It creates another query on DB and then returns only the first line. / P>
It is more concise than writing the whole query every time, but I think I can also call DB too often, is there a better way to output data to my class and yet It is a concrete way to output all rows in brief (perhaps an array of access and return array)? If yes, then how?
You should be able to store the whole object in a variable in a query, then from that object Access:
$ object = $ listing-> GetListingInfo ('', 'Books'); $ Title = $ object- & gt; Title; $ Value = $ item-> value;
But you can also use fetch_assoc () and return the entire associative array:
$ array = $ listing-> GetListingInfo ('', '' Books ''); $ Heading = $ object ['title']; $ Value = $ object ['value'];
This will give you the same results and
Edit with DB only one query: if getListingInfo () is the only function You should think about the following:
- Rename the listing to rename the listingInfo () and just create the query within the function and store it in a square variable.
- Add a getNextListingInfo () function, which will return an object or associate array to the next line.
Using this new function, you can get every row that matches your query.
Comments
Post a Comment