Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-06-2007, 02:18 PM   #1
Registered User
colorada's Avatar
Join Date: Jul 2004
Posts: 53
Send a message via AIM to colorada
Default Edit DataGrid


I need help with finalizing on how to edit the data grid component. I am using PHP and MySQL. Basically I have created a form that writes to a database. I would like to have it set up where the datagrid can be updated and written to the database real time in case an update is required.

define( "DATABASE_SERVER", "localhost" );
define( "DATABASE_USERNAME", "root" );
define( "DATABASE_PASSWORD", "" );
define( "DATABASE_NAME", "sample" );

//connect to the database

mysql_select_db( DATABASE_NAME );

// Quote variable to make safe
function quote_smart($value)
   // Stripslashes
   if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
   // Quote if not integer
   if (!is_numeric($value)) {
       $value = "'" . mysql_real_escape_string($value) . "'";
   return $value;

if( $_POST["emailaddress"] AND $_POST["username"] AND $_POST["sitename"] AND $_POST["wott"] AND $_POST["date"] AND $_POST["resolution"]AND $_POST["complete"]) 
      //add the user
      $Query = sprintf("INSERT INTO users VALUES ('', %s, %s, %s, %s, %s, %s, %s)", quote_smart($_POST['username']), quote_smart($_POST['emailaddress']), quote_smart($_POST['sitename']), quote_smart($_POST['wott']), quote_smart($_POST['date']), quote_smart($_POST['resolution']), quote_smart($_POST['complete']));

      $Result = mysql_query( $Query );

//return a list of all the users
$Query = "SELECT * from users";
$Result = mysql_query( $Query );

$Return = "<users>";

while ( $User = mysql_fetch_object( $Result ) )
      $Return .= "<user><userid>".$User->userid."</userid><username>".$User->username."</username><emailaddress>".$User->emailaddress."</emailaddress><sitename>".$User->sitename."</sitename><wott>".$User->wott."</wott><date>".$User->date."</date><resolution>".$User->resolution."</resolution><complete>".$User->complete."</complete></user>";	
$Return .= "</users>";
mysql_free_result( $Result );
print ($Return)

//FLex 2 AS3 and MMXML
<?xml version="1.0"?>
<!-- Simple example to demonstrate the TabNavigator layout container. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationComplete="userRequest.send()">
		import mx.rpc.events.ResultEvent;
		import mx.collections.*;
		/*import mx.rpc.events.*;*/

		private var mySelectedIndex:int = 0;
		public var techInfo:ArrayCollection;
		private function bookHandler(evt:ResultEvent):void



<mx:HTTPService id="userRequest" url="http://localhost/technician/request.php"  useProxy="false" method="POST">
      <mx:request xmlns="">
 <!--This is the data Provider XML File for Technicians-->  
<mx:Model id="technician" source="techs.xml"/>

 <!--This is the data Provider XML File for Site Information-->  
<mx:Model id="siteInfo" source="sites.xml"/>

    <mx:Panel title="T-Mobile Jacksonville Reporting" height="90%" width="90%" 
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10" x="86" y="-4">

        <mx:TabNavigator id="tn"  width="100%" height="100%" >
            <!-- Define each panel using a VBox container. -->

            <mx:VBox label="Landlink">
                <mx:Label text="Landlink"/>

            <mx:VBox label="Site Source South">
                <mx:Label text="Site Source South"/>

            <mx:VBox label="Field Ops" horizontalAlign="center">
                 <mx:Form width="100%" height="100%" >
                    <mx:Label text="Username     "/>
                 <mx:ComboBox id="username" dataProvider="{technician.tech}" width="170"> 
                    <mx:Label text="Site ID          "/>
                    <mx:ComboBox id="emailaddress" width="170" dataProvider="{siteInfo.SITE}" labelField="site_id" selectedIndex="{mySelectedIndex}" change="mySelectedIndex = ComboBox(event.target).selectedIndex">
                 <mx:Label text="Site Name     "/>
                   <mx:ComboBox id="sitename" width="170" dataProvider="{siteInfo.SITE}" labelField="site_name" selectedIndex="{mySelectedIndex}" change="mySelectedIndex = ComboBox(event.target).selectedIndex">
                 <mx:Label text="WO / TT        "/>
                    <mx:TextInput id="wott" textAlign="left" width="170"/>
                 <mx:Label text="Date             "/>
                    <mx:DateField id="date" width="170"/>
                 <mx:Label text="Resolution     " />
                    <mx:TextInput id="resolution" textAlign="left" width="170"  height="50"/>
                 <mx:Label text="Complete      "/>
                 <mx:ComboBox id="complete"> 
                       <mx:String>Sent to RF</mx:String>
                       <mx:String>Pending Vendor</mx:String>
                 <mx:Button label="Submit" click="userRequest.send()"/>
       <mx:Panel x="343" y="10" backgroundColor="#B3C0C6" title="Trouble Ticket  Tracking" borderAlpha="0.4" borderThicknessBottom="10" width="100%" height="351" layout="absolute">
   	<mx:DataGrid id="dgUserRequest" x="218" y="10" dataProvider="{userRequest.lastResult.users.user}" width="100%" height="100%" editable="true" enabled="true" change="dgUserRequest">
        <!-- <mx:DataGridColumn headerText="User ID" dataField="userid"/>-->
         <mx:DataGridColumn headerText="Technician" dataField="username"/>
         <mx:DataGridColumn headerText="Site ID" dataField="emailaddress"/>
         <mx:DataGridColumn headerText="Site Name" dataField="sitename"/>
         <mx:DataGridColumn headerText="WO / TT" dataField="wott"/>
         <mx:DataGridColumn headerText="Date" dataField="date"/>
         <mx:DataGridColumn headerText="Resolution" dataField="resolution"  /> 
         <mx:DataGridColumn headerText="Complete" dataField="complete"/>    
   	<mx:TextArea id="selectedemailaddress" text="{dgUserRequest.selectedItem.resolution}"  width="200" height="298" x="10" y="10" wordWrap="true" editable="false" enabled="true"/>
            <mx:Canvas label="Generator Fuel Log" width="100%" height="100%">
            	<mx:Label text="Generator Fuel Log"/>

            <mx:Button label="Landlink" click="tn.selectedIndex=0"/>
            <mx:Button label="Site Source South" click="tn.selectedIndex=1"/>
            <mx:Button label="Field Ops" click="tn.selectedIndex=2"/>
            <mx:Button label="Generator Fuel Log" click="tn.selectedIndex=3"/>

colorada is offline   Reply With Quote
Old 08-06-2007, 05:33 PM   #2
drkstr's Avatar
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587

I would create a data model class that is bound to the data grid. Make it so that when the data grid is edited the data model updates as well, which will periodically or instantly send it's data back to the server side script. Keep in mind that listening to a regular change event on a text field will call an action any time a key is pressed.

Let me know if any of this didn't make sense and I'll try to provide some examples.

Best regards,
drkstr is offline   Reply With Quote
Old 08-06-2007, 06:12 PM   #3
Registered User
colorada's Avatar
Join Date: Jul 2004
Posts: 53
Send a message via AIM to colorada

I understand in theory what you mean but I am really new to as3. Basically I need to create a "container" for lack of words and send it back through my php file right? Some examples would be great. I actually started to find a few things on the web that talk about exactly what you are saying but nothing I could really get to work.

I actually just found this http://www.adobe.com/devnet/flex/qui...g_data_models/ still have to work through it "data model" was the key word here. Sometimes you just know how to ask.



Last edited by colorada; 08-06-2007 at 06:14 PM.
colorada is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Proper way to bind data to the DataGrid component - Best practices. andrea_muta Components 1 04-03-2007 09:13 AM
Multiple DataGrid itemEditEnd event when making single edit harvardFlex Flex 2, 3 & 4 4 02-04-2007 12:39 AM
Datagrid Scrolling bug? Column repeats over and over while mouse is pressed... diesel5599 Components 2 12-18-2006 04:34 PM
Please help loading data/ datagrid ericb1 Components 1 11-22-2005 07:26 PM
Pass to edit field from array (DataGrid) QuantumDoja ActionScript 2.0 1 03-22-2005 07:48 PM

All times are GMT. The time now is 09:08 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.