2
votes

Good day. I'm trying to running a query inside loop. Here is what i did so far.

function scan_folder()
{       
    $this->load->library('Word');

    $this->load->helper('directory');
    $map2 = directory_map('./assets/filenya/Hukum Acara', TRUE, TRUE);
    for($x=0;$x<count($map2);$x++)
            {
                    $map3 = directory_map('./assets/filenya/Hukum Acara/'.$map2[$x]);
                    for($xy = 0;$xy<count($map3);$xy++)
                    {

                        $category[$xy] = $this->modelmodel->showsingle("SELECT menu_id FROM kategori 
                                                                where name like '%".stripslashes($map2[$x])."%'");
                        echo $map3[$xy]." ".$category[$xy]->menu_id."<br>";
                    }
            }
}

with my script above. I get this error Trying to get property of non-object.

Array from $map2

Array
(
    [0] => H.I.R\
    [1] => Kitab Undang-Undang Hukum\
)

array from $map3

Array
(
    [0] => KOLONIAL_HERZIEN_INLANDSCH_REGLEMENT.pdf
)
Array
(
    [0] => kolonial_kuh_perdata_fix.pdf
    [1] => KUH DAGANG.pdf
    [2] => KUH PIDANA.pdf
    [3] => KUHAP.pdf
)

And if i just echo the query

echo "SELECT menu_id FROM kategori 
  where name like '%".stripslashes($map2[$x])."%' <br>";

and here is the result

SELECT menu_id FROM kategori where name like '%H.I.R%' 
SELECT menu_id FROM kategori where name like '%Kitab Undang-Undang Hukum%' 
SELECT menu_id FROM kategori where name like '%Kitab Undang-Undang Hukum%' 
SELECT menu_id FROM kategori where name like '%Kitab Undang-Undang Hukum%' 
SELECT menu_id FROM kategori where name like '%Kitab Undang-Undang Hukum%'

here is my error . I'm using Codeigniter 3

KOLONIAL_HERZIEN_INLANDSCH_REGLEMENT.pdf 11 A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/Admin.php

Line Number: 31

Backtrace:

File: D:\xampp\htdocs\jdih\application\controllers\Admin.php Line: 31 Function: _error_handler

File: D:\xampp\htdocs\jdih\index.php Line: 315 Function: require_once

kolonial_kuh_perdata_fix.pdf A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/Admin.php

Line Number: 31

Backtrace:

File: D:\xampp\htdocs\jdih\application\controllers\Admin.php Line: 31 Function: _error_handler

File: D:\xampp\htdocs\jdih\index.php Line: 315 Function: require_once

KUH DAGANG.pdf A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/Admin.php

Line Number: 31

Backtrace:

File: D:\xampp\htdocs\jdih\application\controllers\Admin.php Line: 31 Function: _error_handler

File: D:\xampp\htdocs\jdih\index.php Line: 315 Function: require_once

KUH PIDANA.pdf A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/Admin.php

Line Number: 31

Backtrace:

File: D:\xampp\htdocs\jdih\application\controllers\Admin.php Line: 31 Function: _error_handler

File: D:\xampp\htdocs\jdih\index.php Line: 315 Function: require_once

KUHAP.pdf

1
Which line causes Trying to get property of non-object ?Raptor
post your whole error infoLF00
I think in this line $category[$xy]->menu_id;YVS1102
i've put the error.YVS1102
Which in line 31 ?Raptor

1 Answers

1
votes

Give a try with this

for($x=0;$x<count($map2);$x++)
            {
                    $map3 = directory_map('./assets/filenya/Hukum Acara/'.$map2[$x]);
                    foreach($map3 as $file)
                    {

                        $category = $this->modelmodel->showdata("SELECT menu_id FROM kategori 
                                                                where name like '%".stripslashes($map2[$x])."%'");
                         foreach($category as $result)
                            {
                                echo $file."--".$result->menu_id."<br>";
                            }
                    }
            }