ОК, я новичок в AMFPHP.Я могу сделать простые SQL-заявления без проблем.
Вот мои классы школ и мест:
class Schools {
public $id;
public $district_id;
public $school_name;
// explicit actionscript class
var $_explicitType = "components.Schools";
}
class Locations {
public $id;
public $school_id;
public $school_address;
public $icon_id;
// explicit actionscript class
var $_explicitType = "components.Locations";
}
Это простое SQL-заявление работает без проблем:
/**
* Retrieves schools data
* @returns id, district_id, school_name
*/
public function getSchools() {
//connect to the database.
$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
mysql_select_db(DATABASE_NAME);
//retrieve all rows
$query = "SELECT * FROM schools ORDER BY school_name";
$result = mysql_query($query);
$ret = array();
while ($row = mysql_fetch_object($result)) {
$tmp = new Schools();
$tmp->id = $row->id;
$tmp->district_id = $row->district_id;
$tmp->school_name = $row->school_name;
$ret[] = $tmp;
}
mysql_free_result($result);
return $ret;
}
Однако мне трудно заставить "несколько" сложный SQL-оператор работать должным образом.
/**
* Retrieves schools with locations data
* @returns school_name, school_address
*/
public function getSchoolsLocations() {
//connect to the database.
$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
mysql_select_db(DATABASE_NAME);
//retrieve all schools with their locations
$query = "SELECT schools.school_name AS SNAME, school_address AS SLOC FROM schools, locations WHERE schools.id = locations.school_id";
$result = mysql_query($query);
$ret = array();
while ($row = mysql_fetch_object($result)) {
$tmp = new Schools();
$tmp->id = $row->id;
$tmp->school_name = $row->SNAME;
$ret[] = $tmp;
$tmp2 = new Locations();
$tmp2->school_id = $row->school_id;
$tmp2->school_address = $row->SLOC;
$ret2[] = $tmp2;
array_splice($ret, count($ret), 0, $ret2);
}
mysql_free_result($result);
return $ret;
}
Кстати, SELECT schools.school_name AS SNAME, school_address AS SLOC FROM schools, locations WHERE schools.id = locations.school_id
отлично работает в mysql.