Ma'lumotlar bazasidan ma'lumotlar bo'ylab aylanish

Hey, men o'zgaruvchimda foreach ($report as &rep) yordamida ma'lumotlarga egaman

Ma'lumotlar bazasida 4 xil jadvaldan narsalarni olishni unutmang

Endi $rep-ni chop etganimda men quyidagilarni olaman:

Array
(
    [Report] => Array
        (
            [id] => 246
            [emp] => werock
            [name] => werock
            [organization] => cakephp
            [customer] => great
        )

    [file] => Array
        (
            [0] => Array
                (
                    [id] => 211
                    [report_id] => 246
                    [file_name] => 
                    [file_type] => 
                    [file_size] => 0
                    [file_error] => 4
                    [file_tag] => 0
                )

        )

    [Engineer] => Array
        (
            [0] => Array
                (
                    [id] => 232
                    [report_id] => 246
                )

        )

    [Issue] => Array
        (
            [0] => Array
                (
                    [id] => 118
                    [report_id] => 246
                    [date_created] => 2012-02-10
                    [status] => wait
                )

            [1] => Array
                (
                    [id] => 119
                    [report_id] => 246
                    [date_created] => 2012-02-10
                    [status] => debug
                )

            [2] => Array
                (
                    [id] => 120
                    [report_id] => 246
                    [date_created] => 2012-02-10
                    [status] => Completed

                )

        )

)

Endi men qilmoqchi bo'lgan narsa - Issues massiviga kirish va unda qancha massiv borligini tekshirish. bu holda 3(0,1,2). va bu holatda oxirgi indeks uchun holat qiymatini chop eting(2).

Lekin $rep['Issue']['status'] qilganimda, men Undefined index: statusini olaman. Qayerda xato qilishim mumkinligini ayta olasizmi?


person We Rock    schedule 11.02.2012    source manba


Javoblar (4)


Bu haqida nima deyish mumkin:

echo $rep['Issue'][count($rep['Issue'])-1]['status'];

Ishlasa, menga xabar bering.

person Henri    schedule 11.02.2012

Buni sinab ko'ring

$rep['Issue'][$x]['status'] 

$x o'zgaruvchan bo'lgan joyda siz qiymatlarni olish uchun tsikldan foydalanishingiz mumkin.

person Ajeet Sinha    schedule 11.02.2012

Sizda ikkinchi indeks etishmayapti. Bu shunday bo'lishi kerak:

$rep['Issue'][count($rep['Issue'])-1]['status'].

Buning oʻrniga Set::extract dan foydalanishga urinib koʻrishingiz mumkin. Set klassi massivlar bilan ishlash uchun juda foydali.

$status = Set::extract('/Issue/.[:last]/status', $rep);
if(count($status)){
 // $status[0] == the value of status which is 'Complete' in your example
} else {
 // no issues
}
person Lawrence Barsanti    schedule 11.02.2012
comment
to'plam :: ekstrakti aslida oxirgi o'rniga birinchi yozuvni oladi. - person We Rock; 12.02.2012
comment
Bunga ishonchingiz komilmi? Kecha men ushbu kodni siz joylashtirgan massiv bilan sinab ko'rdim va Set::extract oxirgi yozuvni oldi (masalan, $status[0] == "To'liq"). - person Lawrence Barsanti; 12.02.2012

Agar baham ko'rishni o'ylasam, boshqa usulni sinab ko'rdim.

$endEl[$rep['Report']['id'] ] = end($rep['Issue'] );

Bu yaxshi yo'l bo'lsa, menga xabar bering .. u ishlaydi

person We Rock    schedule 12.02.2012