Welcome Guest, Not a member yet? Register   Sign In
small blog help needed passing data
#11

[eluser]jvicab[/eluser]
try to use if ($data) instead ($data > 0)
check the data returned calling var_dump($data);
just after $data = $this->Entrymodel->sendentry($title, $comment); (before if statement)

in your view you shoud change $data->title for $data[$i].['title'] and the same for body where $i is the element of the array, ie, the row. you can print the first row substituting $i by 0
#12

[eluser]echo sara[/eluser]
Hmm i get null

Code:
$data = $this->Entrymodel->sendentry($title, $comment);
is this the problem?

[code][/
function entrytest($data) {
$this->load->model('Entrymodel');
$title = $this->input->post('title');
$comment = $this->input->post('comment');
$data = $this->Entrymodel->sendentry($title, $comment);
var_dump($data);
if($data) {

echo $data;
$this->load->view('blogentryview', $data);
}
else {
echo "there was no blogs added";

}

}
code]
#13

[eluser]jvicab[/eluser]
did you check if your database has already data on it?
I do not understand why you insert data and after that you pull it from the database to show it
#14

[eluser]Aken[/eluser]
You've got a lot of wrong stuff going on, honestly. You need to read the User Guide more carefully, and start as simple as possible.

Here's some recommended code to get you started (do NOT just copy and paste without figuring out what's going on, or you won't learn anything).

Controller:
Code:
function entrytest()
    {
        $this->load->model('Entrymodel');
        
        $title = $this->input->post('title');
        $comment = $this->input->post('comment');
        
        $this->Entrymodel->add_entry($title, $comment);
        
        $entries = $this->Entrymodel->get_entries();
        
        $data['entries'] = $entries;
        
        $this->load->view('blogentryview', $data);
    }
Model:
Code:
public function add_entry($title, $comment)
    {
        $sql = "INSERT INTO entries (title, body) VALUES ('{$title}', '{$comment}')";
        
        $this->db->query($sql);
        
        return ($this->db->affected_rows() === 1);
    }
    
    public function get_entries()
    {
        $query = $this->db->get('entries');
        
        return $query->result();
    }
View:
Code:
<html>
<head></head>
<body>

<h1>This is the blog page</h1>

&lt;?php if (empty($entries)): ?&gt;

<h3>There are no blog entries</h3>

&lt;?php else:
foreach ($entries as $entry): ?&gt;

<h3>&lt;?php echo $entry->title; ?&gt;</h3>
<h4>&lt;?php echo $entry->body; ?&gt;</h4>

&lt;?php endforeach; endif; ?&gt;

&lt;/body&gt;
&lt;/html&gt;
#15

[eluser]Aken[/eluser]
And for future reference, this is not the appropriate forum section to discuss your application's code. You want to do that here.
#16

[eluser]echo sara[/eluser]
i apologize i though its where we place our codes if we had a issue with this since it was called "Ignited Code"

Ok i understand it alot better now. Thanks. After submitting my title and body; it processed through the functions above and then show the output of everything on my view page. After i refreshed my page and the functions run again so another entry gets placed. How would i prevent that?




Theme © iAndrew 2016 - Forum software by © MyBB