Hi all,
First of all, I’m sure this is an embarrassingly easy issue so I’m sorry for wasting your time with it if it is. I have checked through many forums and googled for hours and still don’t seem to have the answer so I don’t feel so bad for asking.
I’ve just finished the venerable sitepoint guide to building a php database and am trying to apply some of those ideas to a real site I’ve designed…and have fallen at the first hurdle…!
I have made a database with a very simple table - ‘basicelements’ (six rows all with stipulated ids and designated content, ‘basiccontent’.
What I want to do is get a link from my css menu to call up the ‘basiccontent’ from a specified row in the database and display that in the content area of my front page. It’s a simple site which would have been done with static .html pages in the past but I thought this would be a nice way to start off using php. This way I have one html.php page, an index.php page and a .css page. The menu items on the html.php page relate to a row of data in the ‘basicelements’ page which then get brought up as content in the main page. Simple right? Evidently not for me. This is what I have so far, any help would be much appreciated.
php:
if (isset($_GET[‘home’]))
{
$sql = “SELECT basiccontent FROM basicelements WHERE id = ‘1’”;
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = 'Error fetching content for Home Page';
include 'error.html.php';
exit();
}
header('location: .');
exit();
}
while ($row = mysqli_fetch_array($result))
{
$basiccontent = $row[‘basiccontent’];
}
include ‘page.html.php’;
?>
html:
<body bgcolor=“#ffffff” text=“#000000”>
<div id=“headerimage”>
<div>
<ul id=“css3menu”>
<li class="topfirst"><a href="?home" title="home">home</a>
</li>
<li class="topitem"><a href="?aboutus" title="about">about us</a>
<ul>
<li class="subfirst"><a href="?advertising" title="advertising">advertising</a></li>
</ul>
</li>
<li class="topitem"><a href="#" title="journals"><span>journals</span></a>
<ul>
<li class="subfirst"><a href="#" title="2010">2010</a></li>
<li><a href="#" title="2009">2009</a></li>
<li><a href="#" title="2008">2008</a></li>
<li><a href="#" title="2007"><span>2007</span></a>
<ul>
<li class="subfirst"><a href="#" title="winter07">winter</a></li>
<li><a href="#" title="autumn07">autumn</a></li>
<li><a href="#" title="summer07">summer</a></li>
<li><a href="#" title="spring07">spring</a></li>
</ul>
</li>
<li><a href="#" title="archive"><span>archive</span></a>
<ul>
<li class="subfirst"><a href="#" title="archive 0">archive 0</a></li>
</ul>
</li>
</ul>
</li>
<li class="topitem"><a href="?submissions" title="submissions">submissions</a>
</li>
<li class="toplast"><a href="?contactus" title="contact us">contact us</a>
</li>
</ul>
</div>
</div>
<div id=“bodycontent”>
<tr>
<td><?php echo $basiccontent; ?></td>
</td>
<td>column one
</td>
</tr>
</div>
</body>