Welcome Guest, Not a member yet? Register   Sign In
Display results in a table
#1

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

Attached Files
.php   options_view.php (Size: 1.03 KB / Downloads: 48)
.php   site_model.php (Size: 472 bytes / Downloads: 79)
.php   site.php (Size: 724 bytes / Downloads: 62)
Reply
#2

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> 
Web Developer
Reply
#3

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
Reply
#4

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.
On the package it said needs Windows 7 or better. So I installed Linux.
Reply
#5

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB