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

[eluser]max123[/eluser]
How can i display results of a single column in a database table, in a 4 columns table in a view file
#2

[eluser]sofwan[/eluser]
You can try :

in your controller :
function view_table()
{
$query = "select name from student";
$data['resultx']=$this->db->query("$query");
$this->load->view('view_student',$data);
}

in your view (view_student.php)
<?
foreach ($resultx->result() as $row)
{
echo $row->name."<br /> ;
}
?&gt;
#3

[eluser]max123[/eluser]
You didn't get my question. Please read da question.

All the Values from a single column of a table should display in a 4 column table in the view according to the order in the table column
#4

[eluser]renownedmedia[/eluser]
I think the OP needs to learn basic PHP before trying CI.
#5

[eluser]Alninio[/eluser]
When you say 4 columns in order do you mean like a newspaper column layout where you fill the first column then the second then the third and finally the fourth or do you mean row by row?

i.e.

result 1 result 5 result 9 result 13
result 2 result 6 result 10 result 14
result 3 result 7 result 11 result 15
result 4 result 8 result 12 result 16

or

result 1 result 2 result 3 result 4
result 5 result 6 result 7 result 8
result 9 result 10 result 11 result 12
result 13 result 14 result 15 result 16

Either way you can put a counter inside your loop and add in the row/cell tags at the right places.

<edited for layout>
#6

[eluser]jedd[/eluser]
[quote author="max123" date="1258799286"]How can i display results of a single column in a database table, in a 4 columns table in a view file[/quote]

Please show us how you do this in normal / raw PHP - post your existing code - and then we can show you the changes you'd make to work better under CodeIgniter, okay?
#7

[eluser]John_Betong[/eluser]
[quote author="max123" date="1258799286"]How can i display results of a single column in a database table, in a 4 columns table in a view file[/quote]
&nbsp;
A quick search for an old thread on five columns revealed:

http://ellislab.com/forums/viewthread/63078/
&nbsp;

&nbsp;

&nbsp;
#8

[eluser]max123[/eluser]
I found the answer. First the records from the database should take in to an array. There after by using 2 for loops properly showing in the table can be done.

Anyways thanx all for ur support
#9

[eluser]karltingume2007[/eluser]
hey guys!!!

initially i was not part of this problem and solution on showing database results in a table but i was following up closely because i was working on something similar. i have a problem on loading the content of my database unto my view. here is my code:

The controller:
Code:
class Addressbook extends CI_Controller {

public function __construct() {
parent::__construct();
  }
  
public function index() {
$query = "select * from contacts";
    $data['results'] = $this->db->query("$query");
$this->load->view('addressbook_view', $data);

The view:
Code:
&lt;?php

foreach ($results->result() as $row)
  {
    echo $row;  
}
?&gt;

A function in my model:
Code:
function get_entries() {
$query = $this->db->get('contacts');
return $query->result();
}

all of these bring me the following error:
Code:
A PHP Error was encountered

Severity: 4096

Message: Object of class stdClass could not be converted to string

Filename: views/addressbook_view.php

Line Number: 90

please somebody tell me how to convert an object of a class into a string or better still an advanced solution to this problem or how to go about it. Thank you all in advance.






Theme © iAndrew 2016 - Forum software by © MyBB