2

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

6
  • Which line causes Trying to get property of non-object ? Commented Aug 24, 2016 at 2:15
  • post your whole error info Commented Aug 24, 2016 at 2:21
  • I think in this line $category[$xy]->menu_id; Commented Aug 24, 2016 at 2:22
  • i've put the error. Commented Aug 24, 2016 at 2:23
  • Which in line 31 ? Commented Aug 24, 2016 at 2:35

1 Answer 1

1

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>";
                            }
                    }
            }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.