Welcome Guest, Not a member yet? Register   Sign In
[Problem] HTML Table Class
#1

[eluser]Sein Kraft[/eluser]
Hi, everybody...again Tongue

I can't make a table with the rows using a query.

I need obtain something like:
Code:
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td><img src="file_name" /></td><td><img src="file_name" /></td><td><img src="file_name" /></td><td><img src="file_name" /></td>
</tr>
<tr>
<tr>
<td><img src="file_name" /></td><td><img src="file_name" /></td><td><img src="file_name" /></td><td><img src="file_name" /></td>
</tr>
<tr>
<tr>
<td><img src="file_name" /></td><td><img src="file_name" /></td><td><img src="file_name" /></td><td><img src="file_name" /></td>
</tr>
</table>

Using something like the example code, but i can't do that =(

Example code:
Code:
$images = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve');
$new_list = $this->table->make_columns($images, 4);
$table = $this->table->generate($new_list);

The example code cut automaticly the array in four colums.


Model:
Code:
function view()
    {
        $query = $this->db->query("SELECT * FROM imageboard_image LIMIT 10");
                
    foreach ($query->result_array() as $row)
    {
           return $row['id'];
           return $row['file_name'];
           return $row['file_ext'];
           return $row['file_height'];
           return $row['file_width'];
    }

Anybody can help me?
#2

[eluser]Sumon[/eluser]
Here goes your controller
Code:
$this->load->model('test_model');
$images = $this->test_model->all_images();
$this->load->library('table');
$new_list = $this->table->make_columns($images, 4);
echo $table = $this->table->generate($new_list);

and here is your model
Code:
function all_images()
{
  $query = $this->db
        ->from('imageboard_image')
        ->limit(10)
        ->get();
  if ($query->num_rows() > 0)
  {
    $rows = $query->result_array();
    foreach($rows as $row):
        $images[] = '<img src="'.$row['file_name'].'" >';
    endforeach;
    return $images;
  }
  else
  {
    return false;
  }
}
#3

[eluser]Sein Kraft[/eluser]
Thank you, works fine, but the script search the image in the scrpt path, not in base path.

Ex.
http://127.0.0.1/CI/index.php/imageboard...bdc357.jpg

While the images are in:
http://127.0.0.1/CI/images
#4

[eluser]Sumon[/eluser]
you can do it by changing in model
Code:
function all_images()
{
  $query = $this->db
        ->from('imageboard_image')
        ->limit(10)
        ->get();
  if ($query->num_rows() > 0)
  {
    $rows = $query->result_array();
    foreach($rows as $row):
        $images[] = '<img src="http://127.0.0.1/CI/images/'.$row['file_name'].'" >';
    endforeach;
    return $images;
  }
  else
  {
    return false;
  }
}
make sure you not save image path into database. more specifically file_name column contain only file name. not path.

however, this is not a good solution though. better solution is to use a config variable. right now dont have much time to search that. if anyone have an example please post here.
#5

[eluser]Sein Kraft[/eluser]
Yes yes ^^, I only insert the file name, not the file path.

Another fail...

Quote:Fatal error: Call to a member function view() on a non-object in E:\server\htdocs\libelula\system\application\controllers\imageboard.php on line 38

This function show the image in a simple page like "http://www.example.com/imageboard/view/1"

Controller:
Code:
function view($id)
    {    
        $data['id'] = $id;
        $this->model_imageboard->view($data);
        
        $data = array(
                        'view_title' => '$image',
                        'view_heading' => 'Heading',
                        'view_image' => $this->model_imageboard->view()
                     );

        $this->parser->parse('view_imageboard_view', $data);
        
        $this->table->clear();
    }
Model:
Code:
function view($data)
    {
        
        $query = $this->db
        ->select('id, user_id, file_name')
        ->from('imageboard_image')
        ->where('$data['id']')
        ->get();
        
        if ($query->num_rows() > 0)
          {
            $rows = $query->result_array();
            foreach($rows as $row):
            $image = '<img src="http://127.0.0.1/CI/images/'.$row['file_name'].'" title="'.$row['id'].'" >';
            endforeach;
            return $image;
          }
          else
          {
        return false;
          }
    }
#6

[eluser]Sumon[/eluser]
i think, view is a reserver word of CI so try by changing this function name. instead you can use display
#7

[eluser]Sein Kraft[/eluser]
I've change the function name but shows the same error. Tongue
#8

[eluser]Sumon[/eluser]
did you load model name in controller?
Code:
$this->load->model('your_model_name');
in order to call view()function
Code:
$this->your_model_name->view($some_value);
#9

[eluser]Sein Kraft[/eluser]
Now yes x3, but appear an error in the sql query:

Quote:A Database Error Occurred

Error Number: 1054

Unknown column '1' in 'where clause'

SELECT `id`, `user_id`, `file_name` FROM (`imageboard_image`) WHERE `1` IS NULL

Code:
function view($data)
    {
        $id = $data['id'];
        
        $query = $this->db
        ->select('id, user_id, file_name')
        ->from('imageboard_image')
        ->where($id)
        ->get();
        
        if ($query->num_rows() > 0)
          {
            $rows = $query->result_array();
            foreach($rows as $row):
            $image = '<img src="http://127.0.0.1/CI/images/'.$row['file_name'].'" title="'.$row['id'].'" >';
            endforeach;
            return $image;
          }
          else
          {
        return false;
          }
    }
#10

[eluser]Pascal Kriete[/eluser]
Your where clause is wrong.

SQL reads very much like a normal sentence. Right now it reads ... where 1 . Where 1 what?
I think you're looking for ->where('id', $id)




Theme © iAndrew 2016 - Forum software by © MyBB