Welcome Guest, Not a member yet? Register   Sign In
User System
#21

[eluser]plasmagames[/eluser]
ok i forhot a part in the line 14 code so i added it

Code:
<?php foreach($query->results() as $row): ?>

but now it's replaced with this error

Quote:Fatal error: Call to a member function results() on a non-object in /home/pmgames/public_html/code/system/application/views/index.php on line 15

and i think it like that because of the first error.
Quote:Severity: Notice

Message: Undefined variable: query

Filename: views/index.php

Line Number: 15
#22

[eluser]majidmx[/eluser]
could you send the whole section of your code, because I think you're the order of the lines.
#23

[eluser]plasmagames[/eluser]
controller
Code:
<?php

class Psg extends Controller {

    function Psg()
    {
        parent::Controller();
            $config['hostname'] = "localhost";
            $config['username'] = "dbusername";
            $config['password'] = "";
            $config['database'] = "dbdatabase";
            $config['dbdriver'] = "mysql";
            $config['dbprefix'] = "";
            $config['pconnect'] = FALSE;
            $config['db_debug'] = TRUE;
            $config['cache_on'] = FALSE;
            $config['cachedir'] = "";
            $config['char_set'] = "utf8";
            $config['dbcollat'] = "utf8_general_ci";

            $this->load->database($config);
    }

    function index()
    {
        $data['title'] = "Plasma Steel Games | Bring Out Your Inner Gamer!";
        $data['heading'] = "Plasma Steel Games";
        $data['slogan'] = "Bring Out Your Inner Gamer!";
        $query = $this->db->query('SELECT * FROM news');
                
        $this->load->view('index.php', $data, $query);
    }
}

?>

view file
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<center>
<h1>&lt;?=$heading?&gt;</h1>
<h4>&lt;?=$slogan?&gt;</h4>
</center>
<hr />


&lt;?php foreach($query->results() as $row): ?&gt;
<hr />
<h3>&lt;?=$row->title?&gt;</h3>
<h5>&lt;?=$row->author?&gt;</h5>
<hr />
<p>&lt;?=$row->body?&gt;</p>

&lt;?php endforeach; ?&gt;


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

[eluser]majidmx[/eluser]
great,
the way you're passing the data to your view is the problem.
change the controller to this one :
Code:
...
        $data['query'] = $this->db->query('SELECT * FROM news')->results();
                
        $this->load->view('index.php', $data);
...

And in your view :

Code:
...
&lt;?php foreach($query as $row): ?&gt;
...
Let me know if this worked or not.
Let's fix the problem first, then we can discuss the opportunities to improve your code Wink

MajiD Fatemian
#25

[eluser]plasmagames[/eluser]
did't work i get this error:

Fatal error: Call to undefined method CI_DB_mysql_result::results() in /home/pmgames/public_html/code/system/application/controllers/psg.php on line 29
#26

[eluser]majidmx[/eluser]
do it this way :
Code:
$data['query'] = $this->db->query('SELECT * FROM news');
        
        echo('<pre style:"direction:rtl;text-align:left">');print_r($this->db);echo('</pre>');die();

and let me know what you see in the screen, can you paste the whole thing ?
#27

[eluser]davidbehler[/eluser]
Try
Code:
$result = $this->db->query('SELECT * FROM news');
$data['query'] = $result->result_array();
instead of
Code:
$data['query'] = $this->db->query('SELECT * FROM news')->results();
#28

[eluser]majidmx[/eluser]
oh ! there is typo there. It should be :

Code:
$data['query'] = $this->db->query('SELECT * FROM news')->result();

it should be result() not results();
#29

[eluser]plasmagames[/eluser]
thanks man it's working now. Thank you very much
#30

[eluser]plasmagames[/eluser]
K now i would liek to make it so that the way i type the news, it is displayed that way. so like

Welcome To Plasma Steel Games

- Blah Blah Blah
- Blah Blah Blah



Basically the way this forum is




Theme © iAndrew 2016 - Forum software by © MyBB