Welcome Guest, Not a member yet? Register   Sign In
PHP does not run
#1

[eluser]hangbill[/eluser]
Hi
Need some help please.

Running on xampp, localhost.
DB name = manual
table = tbltopic
field = Topic

autoload-> $autoload['libraries'] = array('database');
have set db-> $db['default']['database'] = "manual";

So, seems the db should be available to this project


controller

<?php
class Topic extends Controller {

function Topic()
{
parent::Controller();
}

function index()
{
$query = $this->db->get('tbltopic');
$this->load->view('topic_view', $data);
}
}
?>


view

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;

&lt;head&gt;
&lt;title&gt;Topics&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;?php

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

&lt;/body&gt;
&lt;/html&gt;


Problem is page is blank on url http://localhost/CodeIgniter1.7.2/manual...c_view.php

If I do a straight php echo, eg &lt;?php echo "xxxxxx" ?&gt; it works, but the code above does not return any results. Can anyone see what I am doing wrong.

Thanks
#2

[eluser]imn.codeartist[/eluser]
your problem is at your controller

change your index function to the following and check where you have done wrong.


Code:
function index()
      {
      $data['query'] = $this->db->get(‘tbltopic’);

      $this->load->view(‘topic_view’, $data);
      }
#3

[eluser]hangbill[/eluser]
Thanks for trying to help; it still returns an empty page.
There is a single value in the field 'Topic', which I can see in phpmyadmin, so am expecting the code to send it to the browser. Have checked that there is no whitespace before and after the php tags. Really cant figure this out.
#4

[eluser]Phil Sturgeon[/eluser]
The problem is your URL.

Quote:http://localhost/CodeIgniter1.7.2/manual...c_view.php

You should not access your application like this, it will not work.

Quote:http://localhost/CodeIgniter1.7.2/index.php/topic

Remember that the first segment is the class, the second segment is the method then anything after that is parameters. Your URL has nothing to do with the views at all, they are handled by the controller.

Also, please remember to use the [\code\] tags in your posts.
#5

[eluser]hangbill[/eluser]
Thanks very much, I'll check it out this evening
#6

[eluser]hangbill[/eluser]
I've got it; appreciate your help, thanks very much.




Theme © iAndrew 2016 - Forum software by © MyBB