![]() |
Undefined index - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Undefined index (/showthread.php?tid=32352) |
Undefined index - El Forum - 07-21-2010 [eluser]Unknown[/eluser] I have wrote this: <?php if(count($daftar_dokumen)) { foreach ($daftar_dokumen as $indeks => $list) { $i = $indeks +1 + $on_page; echo "<tr height='30' class='rowJadwal'><td class = 'rowJadwalTepi' width='5'> </td>"; echo "<td align = 'center'>".$i."</td>" ; echo "<td>".anchor("dokumen/detailDokumen/".$list['kode_dokumen'],$list['judul_dokumen'],array('class'=>'linkAllPengumuman'))."</td>"; echo "<td>".$list['nama_kategori_dokumen']."</td>"; echo "<td>".$list['unit_kerja_stis']."</td>"; echo "<td class = 'rowJadwalTepi' width='5'> </td>"; echo "<tr>"; } } ?> And then the warning like this: A PHP Error was encountered Severity: Notice Message: Undefined index: kode_dokumen Filename: dokumen/daftarDokumen.php Line Number: 19 The code i have wrote was implemented to another function and it works but why it can't be at this function? Undefined index - El Forum - 07-21-2010 [eluser]vile[/eluser] [quote author="Axelline" date="1279712795"]I have wrote this: Code: <?php And then the warning like this: A PHP Error was encountered Severity: Notice Message: Undefined index: kode_dokumen Filename: dokumen/daftarDokumen.php Line Number: 19 The code i have wrote was implemented to another function and it works but why it can't be at this function?[/quote] check $list array if it contains $list['kode_dokumen'] index.. Undefined index - El Forum - 07-21-2010 [eluser]KingSkippus[/eluser] Try inserting the following debug line just to test $list at the top of your loop and see if it contains what you expect it to contain: Code: echo '<pre>'.htmlentities(var_export($list, TRUE)).'</pre>'; If it does not have array elements for kode_documen, judul_dokumen, name_kategori_documen, etc., then you will receive the error. If there is a chance that the kode_documen element may be missing but you still need the loop to run anyway with the array keys that do exist, you can do something like this: Code: $kode_document = array_key_exists('kode_documen', $list) ? $list['kode_documen'] : ''; |