2016-11-18 1 views
0

Ich muss wirklich diese Tabelle arbeiten, aber ich kann nicht finden, was in meinem Code fehlt oder warum diese Variable nicht definiert ist. Der Tisch funktioniert gut. Es wird angezeigt und darüber befindet sich ein Suchfeld. Der HTML-Code der Tabelle ist gut, da er die Tabelle anzeigt. Die PHP-Fehler erscheinen innerhalb der Spalten der Tabelle, in der die ID, der Name usw. aufgerufen werden. Bitte Ich brauche Hilfe ..Ein PHP-Fehler wurde festgestellt Schweregrad: Hinweis Nachricht: Undefinierter Index: ID

mein Controller: (tabledisplay.php)

function index() 
    { 
     $data = array(); 
     $this->load->model('table_model'); 
     $data['result'] = $this->table_model->display_table(); 
     $this->load->view('table_view', $data);//error here 

    } 

MY VIEW: (table_view.php)

<table class="table table-hover"> 
       <tr> 
        <th>ID</th> 
        <th>First Name</th> 
        <th>Middle Name</th> 
        <th>Last Name</th> 
        <th>Position</th> 
       </tr> 

       <?php 
       $row = array(); 
       foreach ($row as $result); ?>//the values cannot be displayed 
       <tr> 
        <td><strong><?php echo $row['id']; ?></strong></td>//error starts here 
        <td><?php echo $row['fname']; ?></td> 
        <td><?php echo $row['mname']; ?></td> 
        <td><?php echo $row['lname']; ?></td> 
        <td width="15%"><?php echo $row['position']; ?></td> 
        <td width="100px"><button type="submit" class="btn btn-success">Sign in</button></td> 
       </tr> 
       <?php ?> 

MY MODELL: (table_model.php)

function display_table() 
    { 

    function filterTable($query) 
    { 
     $connect = mysqli_connect("localhost","root","","registerusers"); 

     $filter_Result = mysqli_query($connect, $query); 

     return $filter_Result; 

    } 

     if(isset($_POST['search'])) 
     { 
       $valueToSearch = $_POST['valueToSearch']; 
      // search in all table columns 
      // using concat mysql function 
      $query = "SELECT * FROM `user` WHERE CONCAT(`id`, `fname`, `lname`, `position`) LIKE '%".$valueToSearch."%'"; 
      $search_result = filterTable($query); 
     } 
     else{ 
      $query = "SELECT * FROM `user` LIMIT 10"; 
      $search_result = filterTable($query); 
     } 
    return $search_result; 
    } 

Antwort

2

Sie haben ein $data['result'] auf Controller dort in foreach auf Sicht

Haben $result zuerst in foreach

<?php if ($result) {?> 
<?php foreach ($result as $row) { ?> 
<tr> 
<td><strong><?php echo $row['id']; ?></strong></td> 
<td><?php echo $row['fname']; ?></td> 
<td><?php echo $row['mname']; ?></td> 
<td><?php echo $row['lname']; ?></td> 
<td width="15%"><?php echo $row['position']; ?></td> 
<td width="100px"><button type="submit" class="btn btn-success">Sign in</button></td> 
</tr> 
<?php } ?> 
<?php } else { ?> 
<p>Sorry No Results</p> 
<?php } ?> 

Oder versuchen, wie

<?php if ($result) {?> 
<?php foreach ($result as $row) { ?> 
<tr> 
<td><strong><?php echo $row->id; ?></strong></td> 
<td><?php echo $row->fname; ?></td> 
<td><?php echo $row->mname; ?></td> 
<td><?php echo $row->lname; ?></td> 
<td width="15%"><?php echo $row->position; ?></td> 
<td width="100px"><button type="submit" class="btn btn-success">Sign in</button></td> 
</tr> 
<?php } ?> 
<?php } else { ?> 
<p>Sorry No Results</p> 
<?php } ?> 
+0

ja richtig, @ wolfgang1983 –

+0

die beiden Versuchte^aber Ergebnis ist immer noch nicht definierte Variable .. Dank. Ich habe meine Abfragen bearbeitet und es funktioniert jetzt gut, außer für das Limit von Post, dass es bekommt, ein anderes prob -_- – Distro

Verwandte Themen