0

the problem is global but specifically when creating leaches on blogs & forums... when i run a MySQL query it gets back the results and i display them

like

title - promo text - thumnail\images

and with it i provide a link to page to which i will send the id or something which will again query the DB and fetch the results again and then i will display the complete details... is there ANY way by which i can

query and get all the results and display only desired attributes and when through a link the user goes to the details page the Query Result\Dataset\PHP (Assoc\Array) Array is just transferred by sent to the other page...

one possibility is send passing as parameters via URL\Form -> GET\POST other is store it result in session but wouldn't that increase the size of per session

is there a way... plus please tell me you get what i am trying to do

Moon
  • 19,518
  • 56
  • 138
  • 200
  • That's what databases are for - to serve requests and to bring back reaulsts. There is nothing wrong with it. Millions of siter are serving requests like this. No need to worry. If your query gets slow, you have to optimize it, not cache – Your Common Sense Jan 24 '11 at 08:59

3 Answers3

2

You shouldn't really have to worry about this. But if querying the DB and rendering the page is a performance hit for you (and the data is - mostly - static), then you could start caching either the data or the rendered page itself. Just look into Zend_Cache for an easy, tried-and-tested solution that can handle both of these scenario's.

wimvds
  • 12,790
  • 2
  • 41
  • 42
-1

If you use absolute paths for the images, stylesheets etc it will most probably be cached by browser. Otherwise you can use many of the caching solutions available like memcached. You can also cache images using phpThumb and mod_rewrite as explained here.

TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
-1

I think sessions are your best option in this case:

  • they are much more efficient than database queries
  • using a $_GET array and the URL will have security issues if the data you are sending around is confidential and even if it isn't, it may diminish your users confidence in you if they see their data being passed around for all to see. You also have to be aware of URL length as Internet Explorer has a limit of 2083 characters (http://support.microsoft.com/kb/208427)
  • using $_POST will involve you setting up a (I assume) hidden form on every page a user visits and ensuring that when the user visits a link, the form gets submitted. This just seems like an issue you shouldn't have to deal with.
  • You could use cookies but you have issues again with private data being stored client side. Also, if cookies are large, they will need to be sent to the web server every time you visit a new page increasing the amount of bandwidth being used
  • you could use javascript to populate an empty div on the same page with the extra data rather than have the user leave the page at all. This won't work if the user has javascript switched off though so you would need to implement some other method as well
Matt Asbury
  • 5,644
  • 2
  • 21
  • 29
  • Is it from your personal experience or a result of some long-term education? – Your Common Sense Jan 24 '11 at 09:03
  • 1
    dear @Col. a little explanation goes a long way than the sarcasm. – TheVillageIdiot Jan 24 '11 at 09:09
  • @TheVillageIdiot it's not sarcasm. I am merely wondering, if it's just usual for this site way to answer - directly from imagination, and strictly not from experience. – Your Common Sense Jan 24 '11 at 09:15
  • http://stackoverflow.com/questions/1140808/php-sessions-vs-database, http://support.microsoft.com/kb/208427, http://stackoverflow.com/questions/679701/passing-post-data-from-one-web-page-to-another-with-php, http://stackoverflow.com/questions/359434/cookies-vs-session – Matt Asbury Jan 24 '11 at 09:22
  • With all due respect CS, I tend to take your comments/answers with a pinch of salt. Whilst I believe you to be very good and knowledgeable in what you do, for the majority of the time you decide not to share this and choose to be negative, sarcastic, disagreeable or derogatory. – Matt Asbury Jan 24 '11 at 09:25
  • @Matt as a matter of fact, I shared already in this very question. See my comment to the OP. As for comment to your answer - if you still didn't get it - it's **very simple**: just try not to answer in the cases which aren't coverad by your own experience. – Your Common Sense Jan 24 '11 at 09:50
  • @Col. Is there any part of my answer which you feel is incorrect? – Matt Asbury Jan 24 '11 at 10:02
  • Why do you think the OP refers to the personal data as in your link? Contrary it's general purpose data, seen by everyone, not one person. Why to make multiple caches? – Your Common Sense Jan 24 '11 at 10:15