mprzybylski
02-10-2005, 10:05 PM
ok, i have a database with two tables. one table holds the following:
table 1 name: lots
columns: lot_id, number, description, status_id
table 2 name: status
columns: status_id, name, description
i have a php script that goes as follows (i'm ignoring the description fields for now):
?php
// database connection variables
$server = "localhost";
$username = "*****";
$password = "*********";
$database = "*********";
// database connection statement
$connect = mysql_connect($server, $username, $password);
mysql_select_db($database, $connect);
// get values from the database
$query = "SELECT * FROM lots, status WHERE lots.status_id = status.status_id";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
// loop through database to get the values
for ($i = 0; $i < $num_results; $i++) {
****$row = mysql_fetch_assoc($result);
****$id .= $row['lot_id'] . "\n";
****$lot .= $row['number'] . "\n";
****$lotStatus .= $row['status_id'] . "\n";
}
// output the variables so that flash can read them
$output = "" ;
$output .= "id=" . $id . "&" ;
$output .= "lot=" . $lot . "&" ;
$output .= "lotStatus=" . $lotStatus ;
// echo the final output lines
echo $output;
?>
and the flash file:
// variables for first and last lots
var firstLot:Number = 228;
var lastLot:Number = 481;
// colors array for lot status
// slot0 = empty, slot1 = available, slot2 = sold, slot3 = sale pending
var colors:Array = new Array("", 0x26992F, 0x00FF00, 0x0000FF);
// check the database for the status of the lots
function checkStatus():Void {
for (var i:Number = firstLot; i <= lastLot; i++) {
var targ_mc:String = "lot_" + i;
if (lots.lotStatus == 1) {
// if the lot status is AVAILABLE
var availableColor:Color = new Color(targ_mc);
availableColor.setRGB(colors[1]);
} else if (lots.lotStatus == 2) {
// if the lot status is SOLD
var soldColor:Color = new Color(targ_mc);
soldColor.setRGB(colors[2]);
} else if (lots.lotStatus == 3) {
// if the lot status is SALE PENDING
var pendingColor:Color = new Color(targ_mc);
pendingColor.setRGB(colors[3]);
}
}
}
function loadLots(success:Boolean):Void {
if (success) {
// make sure the php file loaded
lot_txt.text = "lots loaded";
// set variables for data from the database
var lotID = lots.id;
var lotNum = lots.lot;
var lotStat = lots.lotStatus;
checkStatus();
} else {
lot_txt.text = "not loaded";
}
}
var lots:LoadVars = new LoadVars();
lots.onLoad = loadLots;
lots.load("lots.php");
now i'm not 100% sure this script is correct, so if anyone sees problems in it, please do let me know.
anyway, i want to be able to pull out all those fields and load them up in flash so i can use them in the scripts over there. i have a grasp on the LoadVars(); a bit but not sure how to pull all this out and if its correct so that i can use it in flash. the fields im most worried about using is the number field in the lots table and the status_id (in both i guess since its a linking table).
any help would be VERY greatly appreciated. thanks in advance.
table 1 name: lots
columns: lot_id, number, description, status_id
table 2 name: status
columns: status_id, name, description
i have a php script that goes as follows (i'm ignoring the description fields for now):
?php
// database connection variables
$server = "localhost";
$username = "*****";
$password = "*********";
$database = "*********";
// database connection statement
$connect = mysql_connect($server, $username, $password);
mysql_select_db($database, $connect);
// get values from the database
$query = "SELECT * FROM lots, status WHERE lots.status_id = status.status_id";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
// loop through database to get the values
for ($i = 0; $i < $num_results; $i++) {
****$row = mysql_fetch_assoc($result);
****$id .= $row['lot_id'] . "\n";
****$lot .= $row['number'] . "\n";
****$lotStatus .= $row['status_id'] . "\n";
}
// output the variables so that flash can read them
$output = "" ;
$output .= "id=" . $id . "&" ;
$output .= "lot=" . $lot . "&" ;
$output .= "lotStatus=" . $lotStatus ;
// echo the final output lines
echo $output;
?>
and the flash file:
// variables for first and last lots
var firstLot:Number = 228;
var lastLot:Number = 481;
// colors array for lot status
// slot0 = empty, slot1 = available, slot2 = sold, slot3 = sale pending
var colors:Array = new Array("", 0x26992F, 0x00FF00, 0x0000FF);
// check the database for the status of the lots
function checkStatus():Void {
for (var i:Number = firstLot; i <= lastLot; i++) {
var targ_mc:String = "lot_" + i;
if (lots.lotStatus == 1) {
// if the lot status is AVAILABLE
var availableColor:Color = new Color(targ_mc);
availableColor.setRGB(colors[1]);
} else if (lots.lotStatus == 2) {
// if the lot status is SOLD
var soldColor:Color = new Color(targ_mc);
soldColor.setRGB(colors[2]);
} else if (lots.lotStatus == 3) {
// if the lot status is SALE PENDING
var pendingColor:Color = new Color(targ_mc);
pendingColor.setRGB(colors[3]);
}
}
}
function loadLots(success:Boolean):Void {
if (success) {
// make sure the php file loaded
lot_txt.text = "lots loaded";
// set variables for data from the database
var lotID = lots.id;
var lotNum = lots.lot;
var lotStat = lots.lotStatus;
checkStatus();
} else {
lot_txt.text = "not loaded";
}
}
var lots:LoadVars = new LoadVars();
lots.onLoad = loadLots;
lots.load("lots.php");
now i'm not 100% sure this script is correct, so if anyone sees problems in it, please do let me know.
anyway, i want to be able to pull out all those fields and load them up in flash so i can use them in the scripts over there. i have a grasp on the LoadVars(); a bit but not sure how to pull all this out and if its correct so that i can use it in flash. the fields im most worried about using is the number field in the lots table and the status_id (in both i guess since its a linking table).
any help would be VERY greatly appreciated. thanks in advance.