Forum Moderators: coopster

Message Too Old, No Replies

how to construct array

         

recosmic

4:40 pm on Aug 21, 2008 (gmt 0)

10+ Year Member



I retrieve data from database, I think the result is array, how to construct the data-array in php?

PHP Code:
$sql=mysql_query("select * from airline") or die(mysql_error());

if ($sql) {
while($orsCat = mysql_fetch_array($sql)) {

$aid[]=$orsCat['airline'];
$airline[]=$orsCat['airline'];
echo " ¦ airline ".$orsCat["airline"]."<br>";

$sql2=mysql_query("SELECT year(a.tanggal) as year, month(a.tanggal) as month, sum(b.jml) as jml_transaksi, a.airline as airline FROM `keuangan` as a, a_keuangan as b where year(a.tanggal)='2008' and a.id=b.id_transaksi and a.airline=b.id_airline and b.id_airline=".$orsCat["id"]." group by year(a.tanggal), month(a.tanggal), a.airline order by a.tanggal asc") or die(mysql_error());

while($ors = mysql_fetch_array($sql2)){
echo " bulan ".$ors["month"]." ¦ jumlah ".$ors["jml_transaksi"]."<br>";
}
mysql_free_result($sql2);

}

}
In browser like this :

¦ airline Batavia airline
bulan 6 ¦ jumlah 2
bulan 7 ¦ jumlah 2
bulan 8 ¦ jumlah 2
¦ airline Lion Air
bulan 6 ¦ jumlah 1
bulan 7 ¦ jumlah 1
bulan 8 ¦ jumlah 1
¦ airline Sriwijaya Air
bulan 6 ¦ jumlah 1
bulan 7 ¦ jumlah 1
bulan 8 ¦ jumlah 2
¦ airline Garuda
bulan 6 ¦ jumlah 2
bulan 7 ¦ jumlah 2
bulan 8 ¦ jumlah 2

Airline[airline][bulan][jumlah]. Am I correct? How to coding it in php?

cjjer

12:40 am on Aug 22, 2008 (gmt 0)

10+ Year Member



$ar=array();
$ar[]=array('a','b');
$ar[]=array('c','d');
//ect