A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Need advice on storing data in a database instead of using XML files

  1. #1
    Senior Member
    Join Date
    Aug 2004
    Location
    London
    Posts
    410

    Need advice on storing data in a database instead of using XML files

    I have a simple Flash slideshow that reads XML

    The XML files contains a few settings and several data entries

    I want to make it read from a database instead

    I can't make my mind up how I should use the database and how many tables I need

    IMPORTANT: I will have several instances of the same slideshow on several different places - this is what is confusing me how to best store the data

    Any advice would be appreciated

    Thanks


    OM

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Well if its just a simple image slideshow I reckon 1 table should be enough. When you say several instances will they all be on the same website and pulling in the same images or different images for each one. If different then in the database just have a category section column so you can request the appropriate info for each slideshow.

    (Also make your php chuck out XML which has the same schema as your current XML file)
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Senior Member
    Join Date
    Aug 2004
    Location
    London
    Posts
    410
    yes, there will be several instances - all with different settings for each instance and all having different sets of data

    but are you sure one table will be enough?
    i would have thought 2 tables - one for settings and one for data?

    i cant get my head round it at the moment - let me know what u think

    thanks

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    cant be sure .. as i'm not familiar enough with your slideshow.

    What type of different settings are we talking about? Since the different instances are on different pages you can just pass in a query string value telling flash which page it is on and then flash can style it accordingly... u may not necessarily need to put the different settings in the database.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Senior Member
    Join Date
    Aug 2004
    Location
    London
    Posts
    410
    nothing extra ordinary about the xml settings
    for example:

    Code:
    <xml>
       <settings>
          <color>FFFFFF</color>
          <transparency>50</transparency>
          <showborder>true</showborder>
       </settings>
    
       <imageList>
          <image>
             <location>http://www.domain.com/dir1/images/image1.jpg</location>
             <transition>jump</transition>
             <background>true</background>
          </image>
          <image>
             <location>http://www.domain.com/dir1/images/image1.jpg</location>
             <transition>jump</transition>
             <background>true</background>
          </image>
          <image>
             <location>http://www.domain.com/dir1/images/image1.jpg</location>
             <transition>jump</transition>
             <background>true</background>
          </image>
          <image>
             <location>http://www.domain.com/dir1/images/image1.jpg</location>
             <transition>jump</transition>
             <background>true</background>
          </image>
       </imageList>
    </xml>
    I've literally just made the above up
    This would be the XML file for one slideshow

    What I'm saying is that there will be several instances of these

    Anymore thoughts? How many tables would you suggest I need for several instances of the above XML format?

    Thanks

  6. #6
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    You still only need one table: Here's the general idea:

    Suppose you have a slideshow on your about page. This slideshow will call a php file sending/posting it a name/value pair e.g category=about

    Then php will request all the entries from the database whose category is equal to about

    Php will then use the resultant recordset to send back flash generated XML info.

    And then flash will display the information in the slideshow.

    And thats it!!!!

    When you have a slideshow on another page for example the portfolio page, the only difference will be that it will send php the name/value pair category=portfolio


    (regarding the settings part, you can create a separate table in the database called settings - use a category column as a primary key in the settings table and as a foreign key in the slideshow table, and when you make the query select the info from both tables.)

    If the above is a bit confusing you can create a separate settings.xml file instead and then just load this in before loading the info from the database.
    Last edited by silentweed; 03-12-2010 at 05:49 AM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  7. #7
    Senior Member
    Join Date
    Aug 2004
    Location
    London
    Posts
    410
    i understand that
    but surely we need 2 tables because the settings has a different set of fields - this may become quite a lot - say 20 different settings

    and the data might require only 5 fields

    for the sake of being able to update one particular setting or one specific change in the data, surely u need to have 2 tables?

    i suppose i could store everything in strings on one column in the table
    it might take more processing having to rewrite the whole string of settings each time anything is updated?

    what do u think
    let me know
    thanks

  8. #8
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    hi i edited my post while you must have been replying ... have a look and see if it makes more sense
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  9. #9
    Senior Member
    Join Date
    Aug 2004
    Location
    London
    Posts
    410
    thanks
    makes more sense

  10. #10
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    cool if you want to see an example of flash/php/mysql and chucking back XML to flash have a look at my guestbook in my library
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  11. #11
    Junior Member
    Join Date
    Nov 2009
    Location
    UK
    Posts
    22
    I've never had much to do with XML but I'm just finishing a site for photographers where there is one public gallery containing all images and each member has their own gallery just containing their own images. It's all done pretty simply with php and a Flash front end.

    Set up your DB with one table "pictures" and have a couple of columns to identify each specific use of each image. Then the query will pull out whichever images you need to display. Like this:
    Table:


    Sql Query to get ALL images:
    Actionscript Code:
    $sql = mysql_query("SELECT * FROM pictures ORDER BY dtadded DESC");
    //WRITE A STRING (ARRAY) THAT FLASH CAN READ
    $gallery="";
    // LOOP THROUGH THE DB AND MAKE A LIST
    while (($row = mysql_fetch_assoc($sql)) !== false) {
        $imagelist=  $row["dirpath"]. ",";
        $gallery=$gallery.$imagelist;
        }
    // COUNT THE COMMAS IN THE STRING TO GIVE "allpics" TO FLASH as a variable.
    $temp_string=$gallery;
    $all_gallery= substr_count($temp_string,",");

    Then just use Flash Vars to pump the array "gallery" (which is a comma delimited list of all the images) and "all_gallery" (which is the total number of images) into the Flash front end.

    Query for a specific member would be:
    $sql = mysql_query("SELECT * FROM pictures WHERE UID='$id' ORDER BY dtadded DESC");

    Or for a specific set of images (travel in this case) would be:
    $sql = mysql_query("SELECT * FROM pictures WHERE gallery='travel' ORDER BY dtadded DESC");

    See it at work here:
    http://www.shutterbugclub.com/gallery.php

    Hope this helps

    Best wishes
    Monty

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center