Ok guys, I took what you suggested and with some trial and error, I was able to get everything to print out without any errors. I still have one problem though. When the query results get looped and printed, somehow a double of every column value is printed as well. Here is an example of some output:
(it's a table of house listings. The columns are Address, City, State, Year, etc.)
123 N. Ashland St. | 123 N. Ashland St. | Chicago | Chicago | IL | IL | 2003 | 2003
It should be:
123 N. Ashland St. | Chicago | IL | 2003
I can't figure out why since when I do the same exact query in the sqlplus (Oracle database command line) it brings up what it should. Here the code for the entire file in case it's something I'm not seeing.
Code: Select all
<?php
session_name("homelisting");
session_start();
set_include_path('syst:templates');
require_once('db.conf');
require_once('redirect.php');
require_once('template.php');
// Make a connection to the database
$dbconn = oci_connect($dbuser,$dbpass,$sid) or die("Couldn't make a connection!");
$loggedIn = false;
if(!empty($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true){
$loggedIn = true;
}
if(!empty($_SESSION['isAdmin']) && $_SESSION['isAdmin'] == true){
$isAdmin = true;
}else{
$isAdmin= false;
}
$search = empty($_POST['search'])? '' : $_POST['search'];
$action = empty($_POST['action']) ? '' : $_POST['action'];
$display_string = "";
$sql = null;
$result = null;
$parsed = null;
if($action == 'do_search'){
$query = handle_search();
// throw new redirect('search.php');
$parsed = oci_parse($dbconn,$query);
$parsed = empty($parsed)? '' : $parsed;
oci_execute($parsed);
$display_string = "<table border=1 cellpadding=5>\n";
$display_string .= "<tr>\n";
$display_string .= "<th>Address</th><th>City</th><th>State</th><th>Year</th><th>Size</th><th>Bedrooms</th><th>Bathrooms</th><th>Livingrooms</th><th>Basement</th><th>House Type</th><th>Model</th><th>Price</th>\n</tr>\n";
//Loop through the query results and print them in to the table
while ($line = oci_fetch_array($parsed)) {
$display_string .= "<tr>\n";
foreach ($line as $col_value) {
$display_string .= " <td>" . $col_value . "</td>\n";
}
$display_string .= "</tr>\n";
}
$display_string .= "</table>\n";
// Free resultset
oci_free_statement($parsed);
}
// Closing connecion
oci_close($dbconn);
$username = empty($_SESSION['username'])? '' : $_SESSION['username'];
$errMsg = empty($_SESSION['errMsg'])? '' : $_SESSION['errMsg'];
$tmpl = new Template();
$tmpl->parsed = $parsed;
$tmpl->display_string = $display_string;
$tmpl->search = $search;
$tmpl->errMsg = $errMsg;
$tmpl->loggedIn = $loggedIn;
$tmpl->username = $username;
$tmpl->isAdmin = $isAdmin;
print $tmpl->build('banner.tmpl');
print $tmpl->build('search.tmpl');
print $tmpl->build('bottom.tmpl');
function handle_search(){
include_once('safe.php');
$search = $_POST['search'];
$search = safe($search);
$sql = "SELECT address,city,state,yearbuilt,house_size,noofbedrooms,noofbathrooms,nooffamilyrooms,hasbasement,house_type,model,price FROM Houselisting WHERE address LIKE '%" . $search . "%' OR city LIKE '%" . $search . "%' OR state LIKE '%" . $search . "%' OR yearbuilt LIKE '%" . $search . "%' OR house_size LIKE '%" . $search . "%' OR house_type LIKE '%" . $search . "%' OR model LIKE '%" . $search . "%' OR price LIKE '%" . $search . "%'";
return $sql;
}
?>
Usually when I get double output it's because of my loops, but I've checked my loops over and over again and I'm pretty sure it's correct. Any help would be great. Thanks again.