Hi,
I’m experimenting with php and a datagrid component, but it isn’t working out. I want to get the records out of a mysql db and display them in a datagrid.
My php file:
<?
$host="localhost";
$username="";
$password="";
$database="test";
mysql_connect($host,$username,$password)or die(mysql_error("fout bij connectie"));
mysql_select_db($database)or die(mysql_error("fout bij connectie"));
$query = "SELECT Product_id, Product_name, Product_price FROM products ORDER BY Product_id";
$result = mysql_query($query) or die("errotje");
$count = 0;
while($myArray = mysql_fetch_array($result))
{
$Product_id = $myArray['Product_id'];
$Product_name = $myArray['Product_name'];
$Product_price = $myArray['Product_price'];
echo "Product_id$count = Product_id: $Product_id &Product_name$count = Product_name: $Product_name &Product_price$count = Product_price: $Product_price";
$count++;
}
echo "count=$count";
?>
And my as 2.0 class file:
[AS]
class dgPHP {
private var dataContainer:LoadVars;
private var Product_id:Array;
private var Product_name:Array;
private var Product_price:Array;
private var cols:Array;
private var rows:Array;
private var dataGrid;
private var urlPHP:String = "http://localhost/experimenten/DataGrid/dataProvider.php";
function dgPHP()
{
dataContainer = new LoadVars();
try
{
dataContainer.load(urlPHP);
}
catch (Exception:String)
{
trace("Error loading data: "+Exception);
}
placeData();
}
function placeData():Void
{
for(var i:Number=0; i<dataContainer.count; i++)
{
dataGrid.addItem(dataContainer.Product_id*);
dataGrid.addItem(dataContainer.Product_name*);
dataGrid.addItem(dataContainer.Product_price*);
}
}
}
[/AS]
Greetz Ruben de Gooijer