What I'm trying to accomplish here is for a list of aircraft to be downloaded from a database and then for each record to be presented for the user to click. The part I am struggling with is separating each record so it can be used on it's own. All I have currently is two scripts, one php script that queries the database and returns the string of aircraft + attributes:
<?php
// Configuration
$hostname = 'myhost';
$username = 'myusername';
$password = 'mypassword';
$database = 'mydatabase';
try {
$dbh
= new PDO
('mysql:host='. $hostname
.';dbname='. $database, $username, $password
); } catch(PDOException $e) {
echo '<h1>An error has occurred.</h1><pre>', $e->getMessage() ,'</pre>';
}
$sth = $dbh->query(' SELECT * FROM aircraft ORDER BY cost DESC LIMIT 5');
$sth->setFetchMode(PDO::FETCH_ASSOC);
$result = $sth->fetchAll();
if(count($result) > 0) {
foreach($result as $r) {
echo $r['manufac'], " ", $r['model'], " ", $r['cost'], "\n";
}
}
?>
And I also have a controller:
public class aircraftDownloader : MonoBehaviour
{
private string secretKey = "#############";
public string getAircraftURL = "http://cowcatcher.net/am/display.php";
public UILabel aircraftlabel;
void Start()
{
StartCoroutine(GetScores());
}
// remember to use StartCoroutine when calling this function!
IEnumerator GetScores()
{
aircraftlabel.text = "Loading Aircraft Data";
WWW hs_get
= new WWW
(getAircraftURL
); yield return hs_get;
if (hs_get.error != null)
{
print("There was an error getting the high score: " + hs_get.error);
}
else
{
aircraftlabel.text = hs_get.text;
}
}
}
At the moment, all this does is display each record on a new line on a single label. I need some way of seperating each downloaded record so I can use them in separate NGUI buttons/elements. After that I was considering displaying each in a table type format, what's the best way of doing this?
Thanks!