So I am trying to pass data from my controller to my model which will than query the database and return the results back to the controller, then the controller will send them to the view so that they can be displayed however I keep getting a blank page.
This is what my Controller code looks like:
class WelcomePageController extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('guestsearchmodel');
$this->load->helper('url');
}
public function index()
{
$this->load->view('WelcomePageView');
}
public function SearchQuestion()
{
$SearchTerm = $this->input->post('GSearch');
/* Checks to see if a field has been left blank if so then it
* will show and error
*/
if ($SearchTerm == null||$SearchTerm == '')
{
$this->load->view('WelcomePageView');
/* This is a little script that displays an alert
* box on screen when a field has been left blank.
*/
echo '<script type="text/javascript">
window.onload = function () {
alert("No Search Terms Have Been Entered Please Try Again.");
}
</script>';
return false;
}
/* This will call the AddNewUser function from the Model*/
$Term = $this->guestsearchmodel->GuestSearch($SearchTerm);
$data['term'] = $Term;
$this->load->view('GuestSearchResultsView',$data);
}
And this is the code from my model: class guestsearchmodel extends CI_Model {
function __construct()
{
parent::__construct();
$this->load->database();
}
function GuestSearch($Term)
{
$results = "SELECT * FROM Questions WHERE Question Title LIKE '%".$this->db->escape_like_str($Term)."%'";
$data = $results->row_array();
$results->free_result();
return $data;
}
And for reference this is code from my view but none of it displays, it's just a blank screen:
<html>
<head>
<title> My Website </title>
<link rel="stylesheet" href="<?php echo base_url();?>Assets/CSS/SampleCSS.css" type="text/css" />
</head>
<body>
<header>
<ul>
<li><a href="#Login">Login</a></li>
<li><a href="<?php echo base_url();?>index.php/RegisterPageController">Register</a></li>
<li><a href="<?php echo base_url();?>index.php/WelcomePageController">Home</a></li>
</ul>
</header>
<!--This is my Welcome Page View which was loaded by the WelcomePage Controller -->
<h1> Welcome to my Advanced Web Coursework! </h1>
<hr>
<p>The Contents of my Guest Search Result are yet to be decided.</p>
<!--<?php echo $term['Question Title']?>-->
<footer>
Details about my Website
</footer>
P.S: Sorry for any other mistakes or inefficient code, as this is just very early stages of development. Also I am not the best of programmers unfortunately.
EDIT: After Some testing I have discovered that when I add This Code:
$results = "SELECT * FROM Questions WHERE 'Question Title' LIKE '%".$this->db->escape_like_str($Term)."%'";
$data = $results->row_array();
$results->free_result();
return $data;
The page just loads as a blank page, therefore something in this part of the code must be breaking it.