Solved

ASP Datagrid LoadVars NEXT/BACK FUNCTIONS

Posted on 2004-11-02
291 Views
Last Modified: 2008-03-17
Hi All,

I have a quick question.  Using the example from Member Negatyve (http://www.negatyve.com/EE/dg2004aspDB.zip) what if the table held 1,000 or more records.  How could you count al lof the records and load let's say 100 at a time into Flash and/or load into the databgrid?  Is this possible and does anyone have an example?  Any help would be greatly appreciated.

Thanks,

Justice
0
Question by:Justice75
    13 Comments
     
    LVL 16

    Expert Comment

    by:vickerleung
    Justice,

    I think this should be the job of the database script side instead of Flash side

    That means should be the job of the database script to select which 100 records and pass it to Flash

    I can suggest the following code using PHP
    I think if you know the logic, you can apply it to anywhere

    <?
              $start_id = $_POST ["start_id"]; // This line is to get a variable passing from Flash
              $db->set_stmt ("SELECT * FROM DATA_TABLE LIMIT " . $start_id . ", 100"); // This line setup a SQL statement which retrieve the data
                                                                                                                             // the data are stored in that data_table and the place
                                                                                                                             // where the record start to get is the start_id(th) record

              ...... // And then some scripts to print the result back to Flash
    ?>

    So for the Flash side
    First of all you have the start_id variable to indicate the first record id appears in the datagrid
    And then user loadVars post method to call the database script

    e.g.

    data_vars = new LoadVars;
    data_vars.sendAndLoad ("database_script.php",this,"POST");

    And then you may have a previous and next button which
    1. Plus 100 or Minus 100 to the start_id
    2. Rerun the loadvars section

    Hope you got my meaning Justice~!! :)
    Vicker
    0
     

    Author Comment

    by:Justice75
    Hi Vicker!

    I am sorry but I did not understand the PHP.  I use ASP.  I also did not understand what you were saying with the Flash.  Can you help me a bit more?

    Jsutice
    0
     
    LVL 16

    Expert Comment

    by:vickerleung
    Justice,

    Ok I try my best here

    ASP still use SQL statement right??

    say for an example you have 1000 records in the DATA_TABLE

    The following will gives you all the records, right?
    SELECT * FROM DATA_TABLE

    You wanna limit it to 100 records each time only, so in MySQL will be something like this'
    This will gives you the 1st to 100th records
    SELECT * FROM DATA_TABLE LIMIT 100

    And this gives you the 3rd to 102nd records
    SELECT * FROM DATA_TABLE LIMIT 3, 100 // Method A

    Do ASP have something like this??
    If NO! Then simply get all the records and store them into an array

    e.g. data_array [] // which stores all 1000 records inside - Method B

    If you are using Method A, that means you can change the value 3 to any number so that to get which 100 records you wanna have

    And for method B, you can use the following to retrieve those 100 records you wanna have

    starting_position = 3;
    for (temp = 0; temp < 100; temp++)
    {
      data_array_b [temp] = data_array [starting_position];
      starting_position++;
    }

    This way you can get the 3rd to 102nd record in the database

    Hope till this point you got my meaning
    Vicker
    0
     
    LVL 16

    Expert Comment

    by:vickerleung
    Ok, continue in the Flash part.

    Actually you wanna tell the ASP which 100 records you wanna get,
    so you will have a variable first to store that value

    _root.starting_position = 99; e.g. the 99th record

    And you pass this value to ASP using loadVars

    ASP will catch this variable and then put into either Method A or Method B I have mentioned

    Method A
    SELECT * FROM DATA_TABLE LIMIT 99, 100

    Method B
    starting_position = 99;
    for (temp = 0; temp < 100; temp++)
    {
      data_array_b [temp] = data_array [starting_position];
      starting_position++;
    }

    To result the ASP gives you the 99th to 198th records


    So how to control that variable starting_position
    You can simply do so by two buttons (next and previous)

    next_button.onRelease ()
    {
         _root.starting_position = _root.starting_position + 100;
    }

    for previous it is - 100

    So you can get whatever records you wanna have

    I am sorry that I never tried ASP before~
    Vicker
    0
     

    Author Comment

    by:Justice75
    Hi Vickerlung,
    Thanks again for all of your help.

    +++++++++++++_root.starting_position = 99; e.g. the 99th record+++++++++++++++++
    And you pass this value to ASP using loadVars


    Do I add this line to the _root timeline on frame one or do I need to make this is a textbox to hide?  Thanks,

    Justice
    0
     
    LVL 16

    Accepted Solution

    by:
    A variable in root frame is  good enough~ :)

    Vicker
    0
     

    Author Comment

    by:Justice75
    Vicker,

    Can I just set in frame 1 as such :

    _root.starting_position = 99;

    ?
    Justice
    0
     
    LVL 16

    Expert Comment

    by:vickerleung
    Justice

    Sure, that's okay

    But I am thinking is that set to 1 is better?? :p

    Vicker
    0
     

    Author Comment

    by:Justice75
    "But I am thinking is that set to 1 is better?? :p"

    Vicker,
    I am sorry, I dontknow what you mean when you say "set to 1 is better"?  Please let me know so that I dont get messed up later.

    Justice
    0
     
    LVL 16

    Expert Comment

    by:vickerleung
    Justice

    Because probably you will show the first 100 records starting from the record #1 ~~!!! XD

    Vicker
    0
     

    Author Comment

    by:Justice75
    Thanks Vicker,
    I take it and the code will update each 100 records?

    Justice
    0
     
    LVL 16

    Expert Comment

    by:vickerleung
    Justice,

    Can't get your meaning, sorry
    Details please

    Vicker
    0
     

    Author Comment

    by:Justice75
    Hi Vicker,

    "_root.starting_position = 99;"
    starting off should be:  _root.starting_position = 1;
    then I said that the variable _root.starting_position = 101;
    next it will be  _root.starting_position = 201;

    and so on and so on.


    Justice

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
    The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
    The goal of the tutorial is to teach the user how to how to record live broadcast.
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now