2016-03-26 30 views
0

çok büyük bir dizi içine çok boyutlu diziler koymak tek bir durum kimliği ve veritabanı isimleri çektikleri isimleri oluşturmaya çalışıyorum. Benim dizi ben array_push ve dizi birleştirme kullanmaya çalışıyorum buphp mysql veritabanı

$options = array("1" => "Active", "2" => "Inactive"); 

gibi bakıyor çıkıp gerekiyor ama yanlış devam ediyor. İşte

$allStatus = implode(',', array('1', '2')); 
$statuses = $clCont->getAllRecords('*', '`status` WHERE idstatus IN ('.$allStatus.')'); 
$status = mysqli_fetch_assoc($statuses); 


$statusOpt = array(); 
do 
{ 
    array_push($statusOpt[$status['idstatus']],$status['statusName']); 
} 
while ($status = mysqli_fetch_assoc($statuses)); 

$rows = mysqli_num_rows($statuses); 

if($rows > 0) 
{ 
    mysqli_data_seek($statuses, 0); 
    $status = mysqli_fetch_assoc($statuses); 
} 

print_r($statusOpt); 
+0

Yani olsun sonuç nedir? –

+0

Boş bir dizi alıyorum gibi görünüyor Array ( [1] => [2] => ) –

+0

ah tamam ben de alan adını değil kimliği alıyorum. Bunu kontrol ettim ve alan adı var ve sadece –

cevap

0

Tamam ... şimdiye kadar ne var, en kodunuzu değiştirmeye çalışalım:

$allStatus = implode(',', array('1', '2')); 
$statuses = $clCont->getAllRecords('*', '`status` WHERE idstatus IN ('.$allStatus.')'); 
// you don't need to fetch first item. 
// $status = mysqli_fetch_assoc($statuses); 
// and use a do-while loop 
// use just while: 

$statusOpt = array(); 
while ($status = mysqli_fetch_assoc($statuses)) 
{ 
    $id = $status['idstatus']; 
    // The first time you try to put a value in a 
    // $statusOpt[$status['idstatus']] it's not exists, 
    // so you should define it explicitly: 
    if (!isset($statusOpt[$id])) { 
     $statusOpt[$id] = array(); 
    } 

    // after that it should be okay: 
    array_push($statusOpt[$id],$status['statusName']); 
} 

print_r($statusOpt); 
+0

içinde verilen null çok. Bunu tüm yeni projemde kullanmam gerek. Çok büyük bir yardımın var. Tüm mükemmel çalışır –