Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter App getting data from the wrong mySQL table?
#11

[eluser]Adam Griffiths[/eluser]
You can also use

PHP Code:
$this->db->from('content_blog'); 

It might make no difference, but it's something to try.

Oh and I'm still thrown on this line.

PHP Code:
if($id)
{
...


It's really not needed.
#12

[eluser]Dave Blencowe[/eluser]
It was in an earlier version, removed it now.
#13

[eluser]Dave Blencowe[/eluser]
Changing the get_comments function in the model to this:
Code:
function get_comments($id)
    {
        $this->db->order_by('id', 'desc');
        $this->db->where('post_id', $id);
        $this->db->from('content_blog');
        $comments = $this->db->get('content_test');
        
        return $comments->row_array();
    }

Gives me the following error:
Code:
A Database Error Occurred

Error Number: 1052

Column 'id' in order clause is ambiguous

SELECT * FROM (`content_blog`, `content_test`) WHERE `post_id` = '1' ORDER BY `id` desc

[b]EDIT: Ignore that, I'm an idiot lol. Changing it from content_blog to content_test does nothing.
#14

[eluser]xwero[/eluser]
Yes because now you have two tables.

My best guess is that the blog post has no comments.
#15

[eluser]Dave Blencowe[/eluser]
Yeah I saw the error after I posted >_>
And yeah, the blog post doesn't have any comments but why does that make it move to content_blog?
I'm going to insert a piece of data and try it now.

EDIT: Ok, well it seems to be taking the variables/results from both of them...
#16

[eluser]Dave Blencowe[/eluser]
Ok, problem seems to be fixed now I have added data in to the table.
Bit weird to be honest...
#17

[eluser]xwero[/eluser]
And if you remove the comment again?
#18

[eluser]Dave Blencowe[/eluser]
It display data from content_blog
#19

[eluser]xwero[/eluser]
What is the code of the comment view?
#20

[eluser]Dave Blencowe[/eluser]
mdl_blog.php comments function
Code:
function get_comments($id)
    {
        $this->db->order_by('id', 'desc');
        $this->db->where('post_id', $id);
        $comments = $this->db->get('content_test');
        
        return $comments->row_array();
    }

blog.php Comments function
Code:
function comments()
    {
        $this->load->view('template/default/header');
        
        $id = $this->uri->segment(3);    
        $get_blog = $this->mdl_blog->get_blog($id, '1');        

        $get_comments = $this->mdl_blog->get_comments($id);

        $this->load->view('blog/comments/main_view', $get_blog);
        $this->load->view('blog/comments/comments_view', $get_comments);
        $this->load->view('blog/comments/comments_add');
        $this->load->view('template/default/footer');
    }

Comments_view.php
Code:
<br />
<table border="0" cellspacing="3" cellpadding="0" width="600px">
  <tr bgcolor="#AECFF0">
    <td colspan="2">&lt;?php echo $subject; ?&gt;</td>
  </tr>
  <tr bgcolor="#AECFF0">
    <td rowspan="2">&nbsp;</td>
    <td style="padding-left: 10px;">&lt;?php echo(nl2br($comment)); ?&gt;</td>
  </tr>
  <tr bgcolor="#AECFF0">
    <td style="padding-left: 10px;">&lt;?php echo("".$name." - ".$timestamp."");?&gt;</td>
  </tr>

</table>
</center>




Theme © iAndrew 2016 - Forum software by © MyBB