[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Multiple Pages: From php to flash

Can someone help me check the below programme for correction?
I have a program that queries my database (Using flash as my front end).What I want is for  the page to display the 1st few items returned in flash -say 6 items- and the rest will be linked to by <<previous 1-2-3 next>> kind of a thing.
I've written the programme the way i understand and it works partially. The problem is that when I click on the link, <<1-2-3>>, instead of it taking me back to flash to display the items like in the 1st place, it only brings a browser with something like this:

&TotalEntries=6&&GuestBook=Name%3AOla%3Cbr%3EEmail%3Aolootu%40naijanet.com%3Cbr%3EWebsite%3A-%3Cbr%3EComments%3A%3Cb%3EI+love+you++Ayuba%3C%2Fb%3E%3Cbr%3E%3Cfont+size%3D%279%27%3EPosted%3A31%2F12%2F69+16%3A00%3C%2Ffont%3E%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A%3A.%3Cbr%3E%3Cbr%3E&&GuestBook=Name%3AOla%3Cbr%3EEmail%

Below is the programme I used:


?>

$max_results = 6;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);

// Perform MySQL query on only the current page number's results
             

// ###################################################################################
// ########## Reading and Writing the new data to the GuestBook Database #############








$sql = "SELECT * FROM guestBook  LIMIT  $max_results";
$result2 = mysql_query($sql) or die(mysql_error());
$numresult=mysql_num_rows($result2);
if($numresult >0){

$tell .= "$numresult";
print "&TotalEntries=" . urlencode($tell) ."&";
}

  while($row = mysql_fetch_array($result2)){
         
    $GuestBook .= "Name:";
       $GuestBook .=($row["name"]);
   $GuestBook .="<br>";
   
   $GuestBook .="Email:";
    $GuestBook .=($row["email"]);
       $GuestBook .="<br>";
      
    $GuestBook .="Website:";
       $GuestBook .=($row["website"]);
      $GuestBook .="<br>";
      
   $GuestBook .="Comments:<b>";
    $GuestBook .=($row["comments"]);
   $GuestBook .="</b><br>";
   
   $GuestBook .="<font size='9'>Posted:";
    $GuestBook .=strftime("%d/%m/%y %H:%M" , $row["posted"]);
      
$GuestBook .="</font>:::::::::::::::::::.";
$GuestBook .="<br><br>";


      print "&GuestBook=" . urlencode ($GuestBook). "&";
    }
      
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM guestBook"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Page Number Hyperlinks
$GuestBook .= "<b>Select a Page</b>\n";

// Previous Link
if($page > 1){
$prev = ($page - 1);
$GuestBook .="<a href=\"GuestBook3.php"."?page=$prev\"><<Previous</a>&nbsp;";
}
      
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
$GuestBook .= "<b><font color=#FF0000>$i </font></b>";
} else {
$GuestBook .= "<a href=\"GuestBook3.php"."?page=$i\">$i</a> ";
}
if(($i + 30) % 30 == 0)
{
$GuestBook .= 'see';
}
}

// Next Link
if($page < $total_pages){
$next = ($page + 1);
$GuestBook .= "<a href=\"GuestBook3.php"."?page=$next\">Next>></a>";


print "&GuestBook=" . urlencode ($GuestBook). "&";
}      
      
?>
0
olootu
Asked:
olootu
  • 9
  • 8
1 Solution
 
negatyveCommented:
Before looking at php, you should look at what flash does. This is what *I*' d do:

- using loadvars, ask the php page for the count() of how many records you have in your db, and the first six
- display the first six records, then create (in flash) the buttons for the nexts pages
- clicking on the pages buttons, ask the php page for six record starting from (pageNumber - 1) * 6
0
 
olootuAuthor Commented:
Can you please show me samples on how these will work at both ends (flash/php)?
0
 
negatyveCommented:
are you using flash mx or flash mx 2004?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
olootuAuthor Commented:
Am using flashMX
0
 
negatyveCommented:
Download this: http://www.negatyve.com/EE/PageableList.zip

Create a mysql table named People, then feed it with the sql dump and test it..
0
 
olootuAuthor Commented:
Thanks negatyve,
I've tried the above. it populated the 'table' but it only loads 6  items and the links are not working.
Though I don't fully understand the whole flash lots but I can follow it.
0
 
negatyveCommented:
Have you tried calling the getresults.php page alone?
0
 
olootuAuthor Commented:
Yes, I just tried that now. At first it gave me some few error messages, but when I deleted the "mysql_close" statements,  it works fine with the links visible.
My problem now is that I tried to adapt your flash/php code to mine but it seems not to be working.

If you take a look at my codes above, is there a way you could adapt it for me?

This ismy flash code:

on (release) {
      message ="";
message2 ="";
      if(category == ""){
      msg = "Enter a value";
}else{
      loadVariables("http://www.placesandevents.com/quickView2.php", this, "POST");
      message = "Loading...Please wait...";
      //This sends off all the data from the input fields to the php script.
}
}
0
 
negatyveCommented:
I think you should use loadVars in both cases. What kind of input fields are you using?
0
 
olootuAuthor Commented:
Do you mean where I put the variable names? Well, I put them in the 'var' fields.
0
 
negatyveCommented:
What's the connection between those two scripts? Where does the category variable (from flash) fit that php code to?
0
 
olootuAuthor Commented:
I am very sorry for the confusion about the codes from flash. I mistakenly pasted the codes from another project.
Below is the correct flash codes:

on (release) {
      if (Name eq "") {
            _root.Statusb = "Please enter your name";
      } else if (Email eq "") {
            _root.Statusb = "Please enter email Address";
      } else if (Comments eq "") {
            _root.Statusb = "Please enter  your comments";
      } else {
                        _root.GuestBook = "Processing..   Loading New... ";
      loadVariablesNum ("http://www.adewaleayuba.com/GuestBook3.php", this, "POST");
            _root.Status = "Your entry has been submitted.  You should see your comments appear immediately";
            gotoAndStop (2);
      }
}
0
 
negatyveCommented:
I'm sorry too, but my doubt is still here. The php code you provided is to collect guestbook entries only, I cannot see why sending the user name or email to the server...
0
 
olootuAuthor Commented:
Yes, it does collect those variable from flash in the original script I used in my project but i intentionally left that in this example because:

1. I don't want the script to continually inserting empty entries in my database.
2. I am only using this example to see how i can get multiple pages in flash.

See http://www.adewaleayuba.com/fans.php for the real script in action.
0
 
negatyveCommented:
Ok, then the update function in flash should be:

function update(params)
{

      if (Name eq "") {
            _root.Statusb = "Please enter your name";
      } else if (Email eq "") {
            _root.Statusb = "Please enter email Address";
      } else if (Comments eq "") {
            _root.Statusb = "Please enter  your comments";
      } else {
            _root.GuestBook = "Processing..   Loading New... ";
            _root.Status = "Your entry has been submitted.  You should see your comments appear immediately";
            var temp = params.split("|");
            var data_var = new LoadVars();

            data_var.Name = Name;
            data_var.Email = Email

            data_var.limit_start = temp[0];
            data_var.limit_lrows = temp[1];
            data_var.onLoad = function(success)
            {
                  if(success){
                        grid_dg.removeAll();
                        var dp = new Array();
                        for(var i = 0; i < this.limit_lrows; i++)
                        {
                              var item = new Object();
                              item.ID = this["ID" + i];
                              item.Name = this["Name" + i];
                              item.City = this["City" + i];
                              item.Age = this["Age" + i];
                              dp.push(item);
                        }
                        writePagesText(Number(this.total), this.limit_start, this.limit_lrows);
                        grid_dg.setDataProvider(dp);
                  } else {
                        trace("ERROR");
                  }
            };
            data_var.sendAndLoad(phpurl, data_var, "POST");
            gotoAndStop(2);
      }
}
0
 
olootuAuthor Commented:
I am going to adapt the above codes soon, but what about the php scripts? is it  going to remain as the example above or do i need to change anything there?

Thanx
0
 
negatyveCommented:
it will work as in the previous example, but will also receive name and email. Now, what to do with them, I do not know.. :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now