Copy link to clipboard
Copied
If i make a Datagrid with PHP i have this code:
<h2>Submitted forms</h2>
<table>
<tr>
<th>Date</th>
<th>Order ID</th>
<th>Store ID</th>
<th>Route ID</th>
<th>Tech ID</th>
<th>Download PDF</th>
</tr>
<?php
// Start row counter
$iRow = 0;
// Loop through all the rows in the database
while ($orders = mysql_fetch_array($result)) {
$iRow++; // Increase counter
$rowColor = ($iRow % 2) ? "" : "class=\"even\""; // If the row is even, put a CSS class on it
?>
<tr <?php echo $rowColor; // actually put the rowColor class name ?>>
<td><?php echo $orders["date"]; ?></td>
<td><?php echo $orders["id"]; ?></td>
<td><?php echo $orders["store_id"]; ?></td>
<td><?php echo $orders["route_id"]; ?></td>
<td><?php echo $orders["tech_id"]; ?></td>
<td><a href="getorder.php?id=<?php echo $orders['id']; //Download page in this case uses the primary key of the row to select the data to create the pdf. ?>">Download</a></td>
</tr>
<?php
// Close loop
}
?>
I have a column named Download that has a link that runs a php that builds a PDF File and gives it to the user. It works great as above, but I would love to use flex to build an app to do this.
Problem is, I don't understand where I need to add this code in FLEX3. I have just done a simple project where I bult a datagrid that pulls from the MYSQL Database. I am able to add a column with header DOWNLOAD and I see the place where it builds an array, I guess I don't know the syntax to add the link into the array.
I can add more script if needed and greatly apprecite any help ![]()
i have a simple app here that reads information from a database and puts it into a flex datagrid, source code included
http://www.mattlefevre.com/viewExample.php?tut=flexPHP&proj=Simple%20Login%20Application
Copy link to clipboard
Copied
i have a simple app here that reads information from a database and puts it into a flex datagrid, source code included
http://www.mattlefevre.com/viewExample.php?tut=flexPHP&proj=Simple%20Login%20Application
Copy link to clipboard
Copied
Thanks for the link, I am trying to
figure out how to accomplish what I need to do from it.
Here is the php code that Flex generated:
<?php
require_once(dirname(__FILE__) . "/Mascotordersconn.php");
require_once(dirname(__FILE__) . "/functions.inc.php");
require_once(dirname(__FILE__) . "/XmlSerializer.class.php");
/**
* This is the main PHP file that process the HTTP parameters,
* performs the basic db operations (FIND, INSERT, UPDATE, DELETE)
* and then serialize the response in an XML format.
*
* XmlSerializer uses a PEAR xml parser to generate an xml response.
* this takes a php array and generates an xml according to the following rules:
* - the root tag name is called "response"
* - if the current value is a hash, generate a tagname with the key value, recurse inside
* - if the current value is an array, generated tags with the default value "row"
* for example, we have the following array:
*
* $arr = array(
* "data" => array(
* array("id_pol" => 1, "name_pol" => "name 1"),
* array("id_pol" => 2, "name_pol" => "name 2")
* ),
* "metadata" => array(
* "pageNum" => 1,
* "totalRows" => 345
* )
*
* )
*
* we will get an xml of the following form
*
* <?xml version="1.0" encoding="ISO-8859-1"?>
* <response>
* <data>
* <row>
* <id_pol>1</id_pol>
* <name_pol>name 1</name_pol>
* </row>
* <row>
* <id_pol>2</id_pol>
* <name_pol>name 2</name_pol>
* </row>
* </data>
* <metadata>
* <totalRows>345</totalRows>
* <pageNum>1</pageNum>
* </metadata>
* </response>
*
* Please notice that the generated server side code does not have any
* specific authentication mechanism in place.
*/
/**
* The filter field. This is the only field that we will do filtering after.
*/
$filter_field = "store_name";
/**
* we need to escape the value, so we need to know what it is
* possible values: text, long, int, double, date, defined
*/
$filter_type = "text";
/**
* constructs and executes a sql select query against the selected database
* can take the following parameters:
* $_REQUEST["orderField"] - the field by which we do the ordering. MUST appear inside $fields.
* $_REQUEST["orderValue"] - ASC or DESC. If neither, the default value is ASC
* $_REQUEST["filter"] - the filter value
* $_REQUEST["pageNum"] - the page index
* $_REQUEST["pageSize"] - the page size (number of rows to return)
* if neither pageNum and pageSize appear, we do a full select, no limit
* returns : an array of the form
* array (
* data => array(
* array('field1' => "value1", "field2" => "value2")
* ...
* ),
* metadata => array(
* "pageNum" => page_index,
* "totalRows" => number_of_rows
* )
* )
*/
function findAll() {
global $conn, $filter_field, $filter_type;
/**
* the list of fields in the table. We need this to check that the sent value for the ordering is indeed correct.
*/
$fields = array('id','store_id','date','route_id','tech_id','store_name',);
$where = "";
if (@$_REQUEST['filter'] != "") {
$where = "WHERE " . $filter_field . " LIKE " . GetSQLValueStringForSelect(@$_REQUEST["filter"], $filter_type);
}
$order = "";
if (@$_REQUEST["orderField"] != "" && in_array(@$_REQUEST["orderField"], $fields)) {
$order = "ORDER BY " . @$_REQUEST["orderField"] . " " . (in_array(@$_REQUEST["orderDirection"], array("ASC", "DESC")) ? @$_REQUEST["orderDirection"] : "ASC");
}
//calculate the number of rows in this table
$rscount = mysql_query("SELECT count(*) AS cnt FROM `SALLY_ORDERS` $where");
$row_rscount = mysql_fetch_assoc($rscount);
$totalrows = (int) $row_rscount["cnt"];
//get the page number, and the page size
$pageNum = (int)@$_REQUEST["pageNum"];
$pageSize = (int)@$_REQUEST["pageSize"];
//calculate the start row for the limit clause
$start = $pageNum * $pageSize;
//construct the query, using the where and order condition
$query_recordset = "SELECT id,store_id,date,route_id,tech_id,store_name FROM `SALLY_ORDERS` $where $order";
//if we use pagination, add the limit clause
if ($pageNum >= 0 && $pageSize > 0) {
$query_recordset = sprintf("%s LIMIT %d, %d", $query_recordset, $start, $pageSize);
}
$recordset = mysql_query($query_recordset, $conn);
//if we have rows in the table, loop through them and fill the array
$toret = array();
while ($row_recordset = mysql_fetch_assoc($recordset)) {
array_push($toret, $row_recordset);
}
//create the standard response structure
$toret = array(
"data" => $toret,
"metadata" => array (
"totalRows" => $totalrows,
"pageNum" => $pageNum
)
);
return $toret;
}
/**
* constructs and executes a sql count query against the selected database
* can take the following parameters:
* $_REQUEST["filter"] - the filter value
* returns : an array of the form
* array (
* data => number_of_rows,
* metadata => array()
* )
*/
function rowCount() {
global $conn, $filter_field, $filter_type;
$where = "";
if (@$_REQUEST['filter'] != "") {
$where = "WHERE " . $filter_field . " LIKE " . GetSQLValueStringForSelect(@$_REQUEST["filter"], $filter_type);
}
//calculate the number of rows in this table
$rscount = mysql_query("SELECT count(*) AS cnt FROM `SALLY_ORDERS` $where");
$row_rscount = mysql_fetch_assoc($rscount);
$totalrows = (int) $row_rscount["cnt"];
//create the standard response structure
$toret = array(
"data" => $totalrows,
"metadata" => array()
);
return $toret;
}
/**
* constructs and executes a sql insert query against the selected database
* can take the following parameters:
* $_REQUEST["field_name"] - the list of fields which appear here will be used as values for insert.
* If a field does not appear, null will be used.
* returns : an array of the form
* array (
* data => array(
* "primary key" => primary_key_value,
* "field1" => "value1"
* ...
* ),
* metadata => array()
* )
*/
function insert() {
global $conn;
//build and execute the insert query
$query_insert = sprintf("INSERT INTO `SALLY_ORDERS` (id,store_id,date,route_id,tech_id,store_name) VALUES (%s,%s,%s,%s,%s,%s)" , GetSQLValueString($_REQUEST["id"], "int"), #
GetSQLValueString($_REQUEST["store_id"], "int"), #
GetSQLValueString($_REQUEST["date"], "text"), #
GetSQLValueString($_REQUEST["route_id"], "int"), #
GetSQLValueString($_REQUEST["tech_id"], "int"), #
GetSQLValueString($_REQUEST["store_name"], "text")#
);
$ok = mysql_query($query_insert);
if ($ok) {
// return the new entry, using the insert id
$toret = array(
"data" => array(
array(
"id" => $_REQUEST["id"],
"store_id" => $_REQUEST["store_id"], #
"date" => $_REQUEST["date"], #
"route_id" => $_REQUEST["route_id"], #
"tech_id" => $_REQUEST["tech_id"], #
"store_name" => $_REQUEST["store_name"]#
)
),
"metadata" => array()
);
} else {
// we had an error, return it
$toret = array(
"data" => array("error" => mysql_error()),
"metadata" => array()
);
}
return $toret;
}
/**
* constructs and executes a sql update query against the selected database
* can take the following parameters:
* $_REQUEST[primary_key] - thethe value of the primary key
* $_REQUEST[field_name] - the list of fields which appear here will be used as values for update.
* If a field does not appear, null will be used.
* returns : an array of the form
* array (
* data => array(
* "primary key" => primary_key_value,
* "field1" => "value1"
* ...
* ),
* metadata => array()
* )
*/
function update() {
global $conn;
// check to see if the record actually exists in the database
$query_recordset = sprintf("SELECT * FROM `SALLY_ORDERS` WHERE id = %s",
GetSQLValueString($_REQUEST["id"], "int")
);
$recordset = mysql_query($query_recordset, $conn);
$num_rows = mysql_num_rows($recordset);
if ($num_rows > 0) {
// build and execute the update query
$row_recordset = mysql_fetch_assoc($recordset);
$query_update = sprintf("UPDATE `SALLY_ORDERS` SET store_id = %s,date = %s,route_id = %s,tech_id = %s,store_name = %s WHERE id = %s",
GetSQLValueString($_REQUEST["store_id"], "int"),
GetSQLValueString($_REQUEST["date"], "text"),
GetSQLValueString($_REQUEST["route_id"], "int"),
GetSQLValueString($_REQUEST["tech_id"], "int"),
GetSQLValueString($_REQUEST["store_name"], "text"),
GetSQLValueString($row_recordset["id"], "int")
);
$ok = mysql_query($query_update);
if ($ok) {
// return the updated entry
$toret = array(
"data" => array(
array(
"id" => $row_recordset["id"],
"store_id" => $_REQUEST["store_id"], #
"date" => $_REQUEST["date"], #
"route_id" => $_REQUEST["route_id"], #
"tech_id" => $_REQUEST["tech_id"], #
"store_name" => $_REQUEST["store_name"]#
)
),
"metadata" => array()
);
} else {
// an update error, return it
$toret = array(
"data" => array("error" => mysql_error()),
"metadata" => array()
);
}
} else {
$toret = array(
"data" => array("error" => "No row found"),
"metadata" => array()
);
}
return $toret;
}
/**
* constructs and executes a sql update query against the selected database
* can take the following parameters:
* $_REQUEST[primary_key] - thethe value of the primary key
* returns : an array of the form
* array (
* data => deleted_row_primary_key_value,
* metadata => array()
* )
*/
function delete() {
global $conn;
// check to see if the record actually exists in the database
$query_recordset = sprintf("SELECT * FROM `SALLY_ORDERS` WHERE id = %s",
GetSQLValueString($_REQUEST["id"], "int")
);
$recordset = mysql_query($query_recordset, $conn);
$num_rows = mysql_num_rows($recordset);
if ($num_rows > 0) {
$row_recordset = mysql_fetch_assoc($recordset);
$query_delete = sprintf("DELETE FROM `SALLY_ORDERS` WHERE id = %s",
GetSQLValueString($row_recordset["id"], "int")
);
$ok = mysql_query($query_delete);
if ($ok) {
// delete went through ok, return OK
$toret = array(
"data" => $row_recordset["id"],
"metadata" => array()
);
} else {
$toret = array(
"data" => array("error" => mysql_error()),
"metadata" => array()
);
}
} else {
// no row found, return an error
$toret = array(
"data" => array("error" => "No row found"),
"metadata" => array()
);
}
return $toret;
}
/**
* we use this as an error response, if we do not receive a correct method
*
*/
$ret = array(
"data" => array("error" => "No operation"),
"metadata" => array()
);
/**
* check for the database connection
*
*
*/
if ($conn === false) {
$ret = array(
"data" => array("error" => "database connection error, please check your settings !"),
"metadata" => array()
);
} else {
mysql_select_db($database_conn, $conn);
/**
* simple dispatcher. The $_REQUEST["method"] parameter selects the operation to execute.
* must be one of the values findAll, insert, update, delete, Count
*/
// execute the necessary function, according to the operation code in the post variables
switch (@$_REQUEST["method"]) {
case "FindAll":
$ret = findAll();
break;
case "Insert":
$ret = insert();
break;
case "Update":
$ret = update();
break;
case "Delete":
$ret = delete();
break;
case "Count":
$ret = rowCount();
break;
}
}
$serializer = new XmlSerializer();
echo $serializer->serialize($ret);
die();
?>
What I want to do is add a column called Download and then each row needs to have a Link to run a php script, with an id variable on the end so the php can genrate the TCPDF script and make a pdf file. I have a static HTMl based solution:
http://www.mascotconstruction.com/orders/view.php
I just need to figure out the correct syntax to put the link in so FLex will use it,
Copy link to clipboard
Copied
Thanks, this looks good, I have made a simple versio
n that pulls from my db, however, I have an error when I include the link, what is the correct syntax
to pull the link over:
link to php:
http://www.mascotconstruction.com/flex/mascot_orders-debug/vieworders.php
PHP CODE:
<?php
require_once(dirname(__FILE__) . "/Mascotordersconn.php");
$query = "SELECT * FROM SALLY_ORDERS";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo "<user><date>".$row['date']."</date><orderid>".$row['id']."</orderid><storeid>".$row['store_id']."</storeid><routeid>".$row['route_id'].'</routeid><download><a href="http://www.mascotconstruction.com/orders/getorder.php?id='.$row['id'].'" //Download page in this case uses the primary key of the row to select the data to create the pdf.>Download</a></download></user>\n';
}
?>
It works on the php page but when I try to launch the swf it gets:
[RPC Fault faultString="Error #1090: XML parser failure: element is malformed." faultCode="Client.CouldNotDecode" faultDetail="null"]
at mx.rpc.http::HTTPService/http://www.adobe.com/2006/flex/mx/internal::processResult()
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()
at mx.rpc::Responder/result()
at mx.rpc::AsyncRequest/acknowledge()
at DirectHTTPMessageResponder/completeHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
MSML link:
http://www.mascotconstruction.com/flex/mascot_orders-debug/sally.html
CODE:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" verticalAlign="middle" applicationComplete="init()" backgroundGradientColors="[#ffffff, #ffffff]">
<mx:Script>
<![CDATA[
import mx.events.ResizeEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
[
Bindable]
public var date:int;
[
Bindable]
public var orderid:int;
[
Bindable]
public var storeid:int;
[
Bindable]
public var routeid:int;
[
Bindable]
public var techid:int;
[
Bindable]
public var download:String;
[
Bindable]
public var dataDump:String = "dataDump";
private function init():void
{
getUsers.send();
}
private function getUsersResult(evt:ResultEvent):void
{
userDG.dataProvider = evt.result.user;
}
]]>
</mx:Script>
<mx:HTTPService id="getUsers" url="vieworders.php" method="POST" result="getUsersResult(event)">
<mx:request xmlns="">
<data>{dataDump}</data>
</mx:request>
</mx:HTTPService>
<mx:Panel
title="Orders" width="600" height="300" layout="absolute" x="10">
<mx:VBox x="0" y="0" width="596" height="260">
<mx:DataGrid id="userDG" width="596" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="Date" dataField="date"/>
<mx:DataGridColumn headerText="Order ID" dataField="orderid"/>
<mx:DataGridColumn headerText="Store ID" dataField="storeid"/>
<mx:DataGridColumn headerText="Route ID" dataField="routeid"/>
<mx:DataGridColumn headerText="Tech ID" dataField="techid"/>
<mx:DataGridColumn headerText="Download" dataField="download"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
</mx:Panel>
</mx:Application>
Thanks
Copy link to clipboard
Copied
from a quick glance, i think it's this that is throwing the error:
while($row = mysql_fetch_array($result))
{
echo "<user><date>".$row['date']."</date><orderid>".$row['id']."</orderid><storeid>" .$row['store_id']."</storeid><routeid>".$row['route_id'].'</routeid><download><a href="http://www.mascotconstruction.com/orders/getorder.php?id='.$row['id'].'" //Download page in this case uses the primary key of the row to select the data to create the pdf.>Download</a></download></user>\n';
}
you're putting <a href> tags into the xml, which'll make it malformed.
try
while($row = mysql_fetch_array($result))
{
echo "<user><date>".$row['date']."</date><orderid>".$row['id']."</orderid><storeid>".$row['store_id']."</storeid><routeid>".$row['route_id']."</routeid><download>http://www.mascotconstruction.com/orders/getorder.php?id=".$row['id']."</download></user>\n';
}
instead.
Copy link to clipboard
Copied
Got it thanks for the helpful info. I used the link below to make a function that creates a link! And it works!!!
http://www.switchonthecode.com/tutorials/flex-datagrid-goodies-row-color-and-others
Your tutorials and code is pretty nifty, I will be checking out your other project Fo' sho;'!
Flex is pretty awesome! ![]()
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more