Welcome, Guest
  • Author Topic: Flash/PHP number of results from search dislpay  (Read 601 times)

    david*

    • Server what's that
    • *
    • Posts: 6
      • View Profile
      • www.thexperience.co.uk
      • Email
    hello,

    im having a little trouble displaying the number of pages of search results in my flash movie. iv been working on this for a couple of days now and it almost works but not quite!

    i am looking for [1] [2] [3] [4] [5] [6] trype of thing that would be displayed to represent the number of pages of search results.

    here goes....






    ---------------->start php script (display.php)

    if ($i){
    $query = "SELECT * FROM table ORDER BY id ASC LIMIT $i,16";

    } else {
          $query = "SELECT * FROM table ORDER BY id ASC LIMIT 16";
          }



    // Execute query
    $result = mysql_query($query);
    $thisCount = mysql_num_rows($result);


    // If query failed...
    if (!$result) {
        // Inform Flash of error and quit
        fail("Couldn't list threads from database");
    }


    //new quesry to get the total amount of results in the table
    $query2 = "SELECT * FROM table";

    $result2 = mysql_query($query2);

    // get the figure
    $totalCount = mysql_num_rows($result2);

    //calculate the number of pages we will need to display the result
    $calc = ($totalCount / 16);

    //add 1 to the total number of pages for the "for()" loop in flash
    $numpages = ceil($calc) + 1;

    // if there is one page we wont need to display a button to represtent that page
    if ($numpages == 1){
       $numpages == 0;
       }

    // Setup our variable to hold output
    $output = "&totalPages=$numpages&totalHolidays=$thisCount";

    // For each result returned...
    for ($count = 0; $count < $thisCount; $count++)
    {
        // Extract details from database
        $holiday = mysql_fetch_array($result);
       $holidayid = $holiday['holidayid'];
        $destination = $holiday['destination'];
        $hotel = $holiday['hotel'];
       $date = $holiday['date'];
        $flyfrom = $holiday['flyfrom'];
        $duration = $holiday['duration'];
        $price = $holiday['price'];
       
       
       
        // Add details to output
       $output .= "&holiday" . $count . "holidayid=" . $holidayid;
        $output .= "&holiday" . $count . "destination=" . $destination;
        $output .= "&holiday" . $count . "hotel=" . $hotel;
        $output .= "&holiday" . $count . "date=" . $date;
        $output .= "&holiday" . $count . "flyfrom=" . $flyfrom;
        $output .= "&holiday" . $count . "duration=" . $duration;
       $output .= "&holiday" . $count . "price=" . $price;
    }

    // Output all details in one go
    echo $output;

    // Inform Flash of success
    print "&result=Okay";

    // Close link to db
    mysql_close($link);


    ------------------> end PHP












    in  MC "holder" (sitting on the main timeline) in flash we want to load this info into it so we have;





    ----------------> start action script

    rand = Math.random(1000000000);
    loadVariables ("display.php?i=" add i add "&r=" add rand, this);

    if (result == "Okay"){
       gotoAndPlay("display");
    }else{
       nextFrame;
    }

    ----------------> end action script







    inside MC "holder" we have MC "button_holder" to hold all the buttons we get from the php script.  using an attach movie script we attach an MC to represent the buttons.





    ------------> start action script

    //set variable for x co-ords#
    this_nextX= 0;

    //set up loop to creat the amount of buttons
    for (count = 1; count<totalPages; count ++){

       //duplicate the buttonMC to create our 'list' of buttons
       button_holder.attachMovie("page_button", "thepage_button" add count, count);

       //position the MC
       button_holder["thepage_button" add count]._x = this_nextX;

       //set the dynamic text in the button to the page number
       button_holder["thepage_button" add count].number = count;

       //set the new position of the next button
       this_nextX += button_holder["thepage_button" add count]._width +1;

    }




    ----------------------------> end action script




    in the above script we are attaching MC "page_button" to the movie MC "button_holder". we are positioning it and displaying a number in the dynamic text to represent what page the button will display.


    Inside the MC "page_button" there is an invisible button whith the following script attached;



    ------------------------------> start action scritp

    on (release){

        // multiply the number in dynamic txt filed "number" by 15
        point = (this.number * 15);

       // take 15 off this variable 'point' to get the required number for our query string variable to send to display.php
        i = (point - 15);


    //set 'i' in MC "holder" to equal varibale 'i' here
    _parent._parent.i = i

    //move MC "holder" to the required position
    _parent._parent.gotoAndPlay("loop")




    }


    --------------------------------> end action script


    i think thats about all the important parts to this script.


    the problem is;

    i want to display 16 results at a time. so when i play this movie i get 2 pages of results. i ahve 18 results in total.

    everything works as it is supposed to except when i press the buttons. i have to cluck button number 2 twice in order for it to display page 2. then if i want to go pack to page 1 have to click button number 1 twice.

    if i repeat that twice it starts to work fine;

    however if i rapidly and continuiously press either button it will display the oposit page of results.


    so i presure there is a problem with the action script on the button. cause if i query the db manually using display.php it works fine.

    sorry for the long post and i hopt you can understand it easy enough.

    cheers,

    ex1*
    « Last Edit: 11/20/03, 08:07 by david* »

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re:Flash/PHP number of results from search dislpay
    « Reply #1 on: 11/20/03, 13:50 »
    Variables takes some time to load, so using this code

    Quote

    loadVariables ("display.php?i=" add i add "&r=" add rand, this);
    if (result == "Okay"){
      gotoAndPlay("display");
    }else{
      nextFrame;
    }


    You don't give chance to load. You need to setup a loop or a LoadVariables object to perform load, and when result arrives, continue. A tipical loop looks something like this

    [script]
    //frame 1
    loadVariables ("display.php?i=" add i add "&r=" add rand, this);

    //frame 2
    //Nothing here or a "loading" message

    //frame 3
    if (result == "Okay"){
      gotoAndPlay("display");
    }else gotoAndPlay(2)
    [/script]

    Also based on which PHP version are you working on, you need to get $i trough the $_GET array. See http://www.flash-db.com/Board/index.php?board=19;action=display;threadid=3017

    Jorge

    david*

    • Server what's that
    • *
    • Posts: 6
      • View Profile
      • www.thexperience.co.uk
      • Email
    Re:Flash/PHP number of results from search dislpay
    « Reply #2 on: 11/21/03, 04:19 »
    thanks,

    i actually managed to sort it out last night.

    i added a frame set up like you suggested and added an onClipEvent(data) to the MC "holder".

    it all works fine and as expected.

    cheers!

    ex1*