txt = $txt; $this->subs = array(); } }; class Sub { public $nam; public function __construct($nam) { $this->nam = $nam; } }; function load() { $data = array(); $con = new mysqli('localhost', 'root', '', 'Test'); $stmt = $con->prepare('SELECT main.txt,subs.nam FROM main LEFT JOIN subs ON main.id=subs.main_id ORDER BY main.txt;'); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($maintxt, $subnam); $ix = 0; $lastmaintxt = '>>>>BOF<<<<'; while($stmt->fetch()) { if($maintxt != $lastmaintxt) { $ix++; $data[$ix] = new Main($maintxt); $lastmaintxt = $maintxt; } if($subnam != null) $data[$ix]->subs[] = new Sub($subnam); } $stmt->close(); $con->close(); return $data; }; function display_as_lists($data) { echo "
Text | Name |
---|---|
$main->txt | \r\n"; for($ix = 0; $ix < $n; $ix++) { if($ix > 0) echo "|
$sub->nam | \r\n"; } echo "