I need someone to help me with the following problem please:
First of all I have 3 (there are more, but only these 3 files are needed) files:
index.php (this file is composed of several other files with a .inc extension)
cfg_db_connect.php (contains the code to connect to a database. It does work it has been tested)
content.inc (this file is called from the index.php file and displays the content of a page in the web browser)
Here is the code for the file index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="dropdown.js"></script>
<link href="style.css" type="text/css" rel="stylesheet">
<link href="headerstyle.css" type="text/css" rel="stylesheet">
<title>DemoTech Home Page</title>
</head>
<body>
<?php readfile("header.inc");?>
[B]<?php readfile("content.inc");?>[/B]
<?php readfile("sidebar.inc");?>
</div>
<?php readfile("footer.inc");?>
</body>
</html>
Here is the code for the file cfg_db_connect.php:
<?php
function dbopen($hostname, $username, $password )
{
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
return $dbh;
}
function queryInfo()
{
$result = mysql_query("SELECT nws_id, nws_title, nws_posted FROM news");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
print "ID:".$row{'nws_id'}." Title:".$row{'nws_title'}." Posted:".$row{'nws_posted'}."<br>";
}
return $result;
}
function queryInfo2()
{
$result = mysql_query("SELECT nws_title, nws_content, nws_posted FROM news");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
print "<div class=\"post\">
<h2 class=\"title\">
Title:".$row{'nws_title'}."
</h2>
<div class=\"entry\">
".$row{'nws_content'}."
</div>
<p class=\"meta\"><span class=\"byline\">Posted by ".$row{'nws_posted'}." on December 22, 2007</span><a href=\"#\" class=\"comments\">18 comments</a></p>
</div><br>";
}
return $result;
}
function dbclose($dbh)
{
mysql_close($dbh);
}
?>
Here is the code for the file content.inc:
<HEAD>
<link href="style.css" type="text/css" rel="stylesheet">
</HEAD>
<div id="content-wrapper">
<div id="content">
<div class="post">
<?PHP
include ("cfg_db_connect.php");
$username = "xxxx";
$password = "xxxx";
$hostname = "xxxx";
$database = "xxxx"
$connect=dbopen($hostname, $username, $password);
//a database must be selected first
$selected = mysql_select_db($database,$connect) or die("Could not select first_test");
queryInfo2();
dbclose($connect);
?>
</div>
</div>
</div>
Now the problem:
For some reason when I try to run the above files together, the results of the query from the database does not display in the index.php file when the index.php file is run at the server side.
But...
When the code of the file content.inc is copied to the file called index.php, the query seems to be working fine (meaning it displays the contents correctly to the web page), but I don't want to do it this way, because I want the contents to exist in separate files.
Is it possible for someone to explain to me why this is happening?
Thanks in advance