0

I'm about month and a half into PHP. I tried to make function for fetching results from find_all_subjects():

      function find_all_subjects() {
       global $dbconnect;

       $q = "SELECT * FROM subjects ORDER BY id ASC";
       $subject_set = mysqli_query($dbconnect, $q);
       confirm_query($subject_set);
       return $subject_set;

      }

and then making a new function which will loop the result in table rows. The problem is it loops just one result... when I did it with <ul> and <li> it worked fine but it doesn't seem to work when doing it with the table. My table core tags are in another document. So it's not that...

function navigacija() {

               $s         = find_all_subjects();

          while($subjects = mysqli_fetch_assoc($s)) {  

               $out       = "<tr>";

               // Ime Teme

               $out      .= "<td width='25%' height='40'>&nbsp;&nbsp;<a href=\"admin_content.php?subject=" . urlencode($subjects['id']) . "\">";
               $out      .=  $subjects['menu_name'];
               $out      .= "</a></td>";

               // Vidljiva

           if($subjects['visible'] == 1) {
                  $subjects['visible'] = 'DA';
         } else {
                  $subjects['visible'] = 'NE';
         }
               $out      .= "<td width='25%' height='40'><p align=\"center\">DA&nbsp; / &nbsp;NE";
               $out      .= "</p></td>";

               // Broj Strana

               $out      .= "<td width='25%' height='40'>";

               $pages_set = find_sub_from_pages($subjects['id']);

             while($pages = mysqli_fetch_assoc($pages_set)) {  

               $out      .= "<a href=admin_content.php?page=" . $pages['id'] . ">" . $pages['menu_name'] . "</a>";
               $out      .= "</td>";

           }

               // Vidljiva

               $out      .= "<td align=\"center\" width='25%' height='40'>";
               $out      .= "<img width=\"17px\" height=\"17px\" src=\"st/img/ic-arup.png\">
                             </img>&nbsp;<img width=\"17px\" height=\"17px\" src=\"st/img/ic-ardown.png\"></img>&nbsp;";
               $out      .= "</td>";

               $out      .= "</tr>";
             }

              return $out;
 }

1 Answer 1

4

the problem is that you reset

 $out       = "<tr>";

every time in the loop. change this line to

$out       .= "<tr>";

and only put declaration out of the loop

$out       = "";
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.