Home > Back-end >  How do I fetch a table inside an entry in PHP firebase?
How do I fetch a table inside an entry in PHP firebase?

Time:10-03

After successfully inputting data inside a key, I am now facing the problem of trying to display it.

Table

this is the code that I've been trying and modifying to try and fetch it but to still to no avail

<tr> 
     <th>Course Code</th>
     <th>Discriptive Title</th>
     <th>Unit</th>
     <th>Pre-Requisite</th>
     <th>Grade</th>
 </tr>
 <?php
 include('dbcon.php');
     if(isset($_GET['id']))
      {
         $key_child = $_GET['id'];
         $ref_table = 'User'.$key_child.'/Grades/1st Year/1st Sem';
         $fetchdata = $database->getReference($ref_table)->getChild($key_child)->getValue();
     if($fetchdata > 0)
         {
             $i = 0;
             ?>
              <input type="hidden" name = "id" value = "<?=$key_child;?>">
             <?php
                 foreach($fetchdata as $key_child => $row)
                     {
                     ?>
                 <tr>
                     <td> <?= $row['Course_Code'];?> </td>
                     <td> <?= $row['Desc_title'];?> </td>
                     <td> <?= $row['Unit'];?> </td>
                     <td> <?= $row['Pre-Req'];?> </td>
                     <td> <?= $row['Grade'];?> </td>
                     </td>
                 </tr>
                     <?php
         }
     }
     else
     {
         ?>
         <td colspan = "5"> Nothing Found </td>
         <?php
     }
 }
 else
         {
         ?>
             <td colspan = "5"> No Record found </td> 
         <?php
 }

It is displaying the "Nothing Found" when I execute it even though there are data in the database.

And this is the code that I initially tried for some context.

 <tr> 
     <th>Course Code</th>
     <th>Discriptive Title</th>
     <th>Unit</th>
     <th>Pre-Requisite</th>
     <th>Grade</th>
 </tr>
$key_child = $_GET['id'];
 $ref_table = 'User'.$key_child.'/Grades/1st Year/1st Sem';
 $getdata = $database->getReference($ref_table)->getChild($key_child)->getValue();
 if($getdata > 0)
 {
  ?>
     <input type="hidden" name = "id" value = "<?=$key_child;?>">
     <tr>
         <td> <?= $row['Course_Code'];?> </td>
         <td> <?= $row['Desc_title'];?> </td>
         <td> <?= $row['Unit'];?> </td>
         <td> <?= $row['Pre-Req'];?> </td>
         <td> <?= $row['Grade'];?> </td>
         </td>
     </tr>

CodePudding user response:

If $key_child is 5nKX..., then you're missing a / after User in this code:

$ref_table = 'User'.$key_child.'/Grades/1st Year/1st Sem'

So to fix that problem:

$ref_table = 'User/'.$key_child.'/Grades/1st Year/1st Sem'
//                           
  • Related