foreach() argument must be of type array|object, bool given. How can i join another table where a where clause also must be there.?

 $SQL = "SELECT * FROM note_list JOIN `notemaker_tables` ON note_list.notemaker_id=notemaker_tables.notemaker_id WHERE notemaker_id = '$notemaker_id';";
    $result = $con->query($SQL);
    
        ?>
        <?php
        
                <!-- Featured Project Row-->
                
                <h1 class="text-white">Notes By <?php echo $notemaker_id; ?></h1><br>
                <?php
                
                foreach ($result as $r) {
                    ?>
                     <div class="row align-items-center no-gutters mb-4 mb-lg-5">
                    <div class="col-xl-8 col-lg-7"> <iframe id="pdf-js-viewer" src="dashboard/note-pdf/<?php echo $r['note']; ?>" title="webviewer" frameborder="0" width="500" height="600"></iframe></div>
                     <div class="col-xl-4 col-lg-5">
                        <div class="featured-text text-center text-lg-left">
                          <p class="text-white"> <?php echo $r['uni_id']; ?> University <br><?php echo $r['depart_id']; ?> Department<br><?php echo $r['subject_id']; ?> Subject<br> <?php echo $r['semester']; ?> Semester</p><br>
                <a href="dashboard/note-pdf/<?php echo $r['note']; ?>" target="_blank" class="btn btn-success">FullScreen</a><br><br><br><br><br><br></div></div>
            </div>
            <hr style="border-width:2;color:white;background-color:white"><br>
                <?php
 }
    } 
    
  }
 ?>

i have to use a where clause also and have to join two tables too.how can i do that.when i write as given , it says foreach() argument must be of type array|object, bool given.when i remove the join statement, the code works.

>Solution :

in case $result = $con->query($SQL); is bool (ex false), your query or database connection is failed.

in your WHERE clause the notemaker_id have no table name, replace it with note_list.notemaker_id and it should work.

Leave a Reply