CodeIgniter Forums

Full Version: Display results in a table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have made a simple CRUD site, i have attached files, i would like to be able to display results in a table, is this possible? how would i apply this to my code? 
any guidance will be helpful.

Thank You
On your VIEW options_view.php page

PHP Code:
<!DOCTYPE html>
<
html lang="en">
<
head>
    <
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
title>Untitled</title>
    <
style type="text/css" media="screen">
        
label{display:block;}
    </
style>
</
head>
<
body>
<
h2>Create</h2>
<?
php echo form_open('site/create');?>
<p>
<label for="title">Title:</label>
<input type="text" name="title" id="title" />
</p>
<p>
<label for="content">Content:</label>
<input type="text" name="content" id="content" />
</p>
<p>    
    <input type="submit" value="submit" />    
</p>
<?php echo form_close(); ?>
<hr />
<h2>Read</h2>
<table class="table">
    <thead>
      <tr>
        <th>Title</th>
        <th>Content</th>
      </tr>
    </thead>
    <tbody>
    <?php if(isset($records)) : foreach($records as $row) : ?>
      <tr>
        <td><?php echo anchor("site/delete/$row->Id"$row->title); ?> </td>
        <td><?php echo $row->content?></td>
      </tr>
     <?php endforeach; ?>
     <?php else : ?>
    <tr>
        <td><h2>No records returned.</h2></td>
    </tr>
    <?php endif; ?>
    <tr>
        <td><h2>Delete</h2></td>
    </tr>
  </table>
<hr />
<h2></h2>
<p>To sample the delete method, click on on of the headings above.
A delete query will automatically run.
</p>
</body>
</html> 
rename the files:
- site_model.php to Site_model.php
- site.php to Site.php

In you view:
anchor("site/delete/$row->Id", $row->title); to anchor("site/delete/".$row->id, $row->title);

Is it Id or id? because in you view $row->Id and in you model it called id
Just to point out again what Paranight mentioned.

$row->Id and $row->id or site.php and Site.php will work on windows machines regardless, but on a real server these things are different and will cause problems. Pay attention to your spelling. Linux is case-sensitive regarding file names and in most case also for field and table names.
(06-21-2017, 02:41 AM)rtenny Wrote: [ -> ]Just to point out again what Paranight mentioned.

$row->Id and $row->id  or site.php and Site.php will work on windows machines regardless, but on a real server these things are different and will cause problems. Pay attention to your spelling. Linux is case-sensitive regarding file names and in most case also for field and table names.

$row->Id and $row->id is not the same on a windows system too.