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*