By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,719 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,719 IT Pros & Developers. It's quick & easy.

LoadVars Datagrid can not populate second Datagrid

P: 63
Hi everyone and I hope that you can help.

I am trying to send a value of a cell within a Datagrid to my php file which has a simple sql query:

here's the php:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3.  
  4.     $server = "localhost";
  5.     $username = "username";
  6.     $password = "password";
  7.     $database = "mydb";
  8.     $file = $_POST['file'];
  9.  
  10.     if (!mysql_connect($server, $username, $password)) 
  11.     {
  12.        $r_string = '&errorcode=1&';    
  13.     } 
  14.     elseif (!mysql_select_db($database)) 
  15.     {
  16.        $r_string = '&errorcode=2&';
  17.     } 
  18.     else 
  19.     {
  20.        $qr = mysql_query("SELECT * FROM  `casting_registration` WHERE  `PICTURE` LIKE CONVERT( _utf8 '".$file."'
  21. USING latin1 ) COLLATE latin1_swedish_ci LIMIT 0 , 30");
  22.        if (!qr || mysql_num_rows($qr)==0) 
  23.        {
  24.          // $r_string = '&errorcode=3&msg='.mysql_error().'&';
  25.        } 
  26.        else 
  27.        {
  28.  
  29.           $r_string = '&errorcode=0&n='.mysql_num_rows ($qr);
  30.         //  $i = 0;
  31.           while ($row = mysql_fetch_assoc ($qr)) 
  32.           {
  33.              while (list ($key, $val) = each ($row)) 
  34.              {
  35.                 $r_string .= '&' . $key . $count. '=' . stripslashes($val);
  36.              }
  37.             // $i++;
  38.           }
  39.           // add extra & to prevent returning extra chars at the end
  40.           $r_string .='&';
  41.        }
  42.        echo $r_string.'<br>&nbsp;<br>'.$file;
  43.     }
  44.  
  45. ?>
  46.  
  47.  
Basically it should come back with a string that I use to populate my datagrid. I know that the query works fine and I've used php files to load datagrids before, so I'm assuming the issue is with my Actionscript

here's actionscript for sending the file variable to the php file, which uses the "cellpress" function via the datagrid to send the file name to the php file to run it's select statement:
Expand|Select|Wrap|Line Numbers
  1.  
  2. function defineListener() 
  3. {
  4. var myListener = new Object();
  5.     myListener.cellPress = function(eObj) 
  6.     {
  7.          et = eObj.target;
  8.          var cell = "(" + eObj.columnIndex + ", " + eObj.itemIndex + ")";
  9.          // trace(" The cell at " + cell + " has been clicked ");
  10.          // trace("Cell Text: " + et.getItemAt( eObj.itemIndex)[et.getColumnAt(eObj.columnIndex).columnName] );
  11.          var myFile =  et.getItemAt( eObj.itemIndex)[et.getColumnAt(eObj.columnIndex).columnName];
  12.          var imageSource:String = 'http://www.mydomain.com/registration/images/' +  et.getItemAt( eObj.itemIndex)[et.getColumnAt(eObj.columnIndex).columnName];
  13.          image1.load(imageSource);
  14.    dataOut.file = myFile.text;
  15.    trace(dataOut.file);
  16.    dataOut.sendAndLoad("http://www.mydomain.com/server/image_readere.php", select_lv, "POST");
  17. };
  18. dataGridMain.addEventListener("cellPress", myListener);
  19. }
  20.  
  21.  defineListener();
  22.  
  23. var dataOut:LoadVars = new LoadVars();
  24.  
  25.  
  26.  
here's actionscript for receiving the string from the php file:
Expand|Select|Wrap|Line Numbers
  1.  
  2. var castingInfo:Array = [];
  3.  
  4. select_lv.onLoad = function(ok:Boolean) 
  5. {
  6.    if (ok) 
  7.    {
  8.       if (this.errorcode=="0") 
  9.       {
  10.          for (var i:Number=0; i < this.n; i++) 
  11.          {
  12.             castingInfo.push(
  13.                {SHOWS:this["SHOWS"+i],
  14.                GENDER:this["GENDER"+i],
  15.                AGE:this["AGE"+i],
  16.                 FIRST_NAME:this["FIRST_NAME"+i],
  17.                 LAST_NAME:this["LAST_NAME"+i],
  18.                 EMAIL_ADDRESS:this["EMAIL_ADDRESS"+i],
  19.                 PHONE_NUMBER:this["PHONE_NUMBER"+i],
  20.                 CITY:this["CITY"+i],
  21.                 STATE:this["STATE"+i],
  22.                 ZIP:this["ZIP"+i],
  23.                 PICTURE:this["PICTURE"+i]});
  24.          }
  25.  
  26.  
  27.          casting_dg.columnNames = ["SHOWS","GENDER","AGE","FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS","PHONE_NUMBER","CITY","STATE","ZIP","PICTURE"];
  28.  
  29.          casting_dg.getColumnAt(0).width = 200;
  30.          casting_dg.getColumnAt(0).sortOnHeaderRelease = false;
  31.          casting_dg.getColumnAt(0).sortedUp = false;
  32.          casting_dg.getColumnAt(0).headerText = "SHOWS";
  33.  
  34.          casting_dg.getColumnAt(1).width = 50;
  35.          casting_dg.getColumnAt(1).sortOnHeaderRelease = false;
  36.          casting_dg.getColumnAt(1).sortedUp = false;
  37.          casting_dg.getColumnAt(1).headerText = "GENDER";
  38.  
  39.          casting_dg.getColumnAt(2).width = 30;
  40.          casting_dg.getColumnAt(2).sortOnHeaderRelease = false;
  41.          casting_dg.getColumnAt(2).sortedUp = false;
  42.          casting_dg.getColumnAt(2).headerText = "AGE";
  43.  
  44.          casting_dg.getColumnAt(3).width = 50;
  45.          casting_dg.getColumnAt(3).sortOnHeaderRelease = false;
  46.          casting_dg.getColumnAt(3).sortedUp = false;
  47.          casting_dg.getColumnAt(3).headerText = "FIRST_NAME";
  48.  
  49.          casting_dg.getColumnAt(4).width = 75;
  50.          casting_dg.getColumnAt(4).sortOnHeaderRelease = false;
  51.          casting_dg.getColumnAt(4).sortedUp = false;
  52.          casting_dg.getColumnAt(4).headerText = "LAST_NAME";
  53.  
  54.          casting_dg.getColumnAt(5).width = 200;
  55.          casting_dg.getColumnAt(5).sortOnHeaderRelease = false;
  56.          casting_dg.getColumnAt(5).sortedUp = false;
  57.          casting_dg.getColumnAt(5).headerText = "EMAIL_ADDRESS";         
  58.  
  59.          casting_dg.getColumnAt(6).width = 100;
  60.          casting_dg.getColumnAt(6).sortOnHeaderRelease = false;
  61.          casting_dg.getColumnAt(6).sortedUp = false;
  62.          casting_dg.getColumnAt(6).headerText = "PHONE_NUMBER";    
  63.  
  64.          casting_dg.getColumnAt(7).width = 100;
  65.          casting_dg.getColumnAt(7).sortOnHeaderRelease = false;
  66.          casting_dg.getColumnAt(7).sortedUp = false;
  67.          casting_dg.getColumnAt(7).headerText = "CITY";    
  68.  
  69.          casting_dg.getColumnAt(8).width = 50;
  70.          casting_dg.getColumnAt(8).sortOnHeaderRelease = false;
  71.          casting_dg.getColumnAt(8).sortedUp = false;
  72.          casting_dg.getColumnAt(8).headerText = "STATE";    
  73.  
  74.          casting_dg.getColumnAt(9).width = 25;
  75.          casting_dg.getColumnAt(9).sortOnHeaderRelease = false;
  76.          casting_dg.getColumnAt(9).sortedUp = false;
  77.          casting_dg.getColumnAt(9).headerText = "ZIP";    
  78.  
  79.          casting_dg.getColumnAt(10).width = 300;
  80.          casting_dg.getColumnAt(10).sortOnHeaderRelease = false;
  81.          casting_dg.getColumnAt(10).sortedUp = false;
  82.          casting_dg.getColumnAt(10).headerText = "PICTURE";     
  83.  
  84.          casting_dg.dataProvider = castingInfo;
  85.  
  86.         //casting_dg.addEventListener("headerRelease", headerListener);
  87.  
  88.  
  89.          msg_ta.text = "Ready...";
  90.  
  91.       } 
  92.       else 
  93.       {
  94.          // show kind of error
  95.          msg_ta.text = errorMsgs[Number(this.errorcode)];
  96.          // if query error, show mysql_error
  97.          if (this.errorcode == "3") msg_ta.text += ": " + this.msg;
  98.       }
  99.    } 
  100.    else 
  101.    {
  102.       // if loadvars failed (eg, if script not found)
  103.       msg_ta.text = "Flash-database select operation failed";
  104.    }
  105.  
  106. }
  107. msg_ta.text = "Getting info from database...";
  108. msg_ta.setStyle("backgroundColor", 0x000000); 
  109. msg_ta.setStyle("fontFamily", Verdana);
  110. msg_ta.setStyle("color", 0x5AF416); 
  111. select_lv.sendAndLoad("http://www.mydomain.com/server/image_readere.php", select_lv, "GET");
  112.  
  113.  
I've used this very same code for populating another datagrid in another application, but I called the above code immediately, whereas with this app, I only want it to be called after I've called the "cellpress" function by clicking on one of the cells within the first datagrid.
Oct 23 '07 #1
Share this Question
Share on Google+
1 Reply


P: 63
False alarm, I forgot the loadVars

Expand|Select|Wrap|Line Numbers
  1.  
  2. var select_lv:LoadVars = new LoadVars();
  3.  
  4.  
Thanks as usual :-)
Oct 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.