SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2006
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    values from mysql into function

    Hello,

    I am creating a form which has a select option, the select option data can be obtained from a database, but I don't want to connect to the database just for each user of the website just to get the options that seldom changes. I can hardcore it into the function, but it means that I will have to keep monitoring the database to determine when changes occur (I won't be inputting data into the database). I tried creating a script that will obtain the values from the database once a week, put it into a static page, and then the function can use the information in it, but having difficulty putting the database info into a web page that the php function can read.

    Any ideas how I can create it, or should I just create a script that e-mails me when the database has been changed and then change the function?

    Any ideas appreciated.

    Thanks,

    CathyM

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I imagine you've made a script to create a cache for the options as a ready html saved in a file, that updates whenever you change the db.

    So you want to include that cached html in your pages. That's what your function should do. This function doesn't need anything but the filename to read and return it's contents where needed. Or depending on your architecture, you can perhaps simple 'include' the cached file where options are necessary.
    Saul

  3. #3
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Here's how I would do it:

    Create a cache file of the options from the database, if it doesn't exist, and use it. If it already exists, use it anyway.

    When updating the database, have the script delete the cache file. That way it would get recreated the next time someone tries to access that page with the options.

    Having said that, depending on the size of the site, querying the database every time won't be that much of an overhead really. Some applications run hundreds, even over 1000 queries in one page.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •