Ok, not sure if this is exactly possible, but, knowin you guys, one of you can help.
See, I read somewhere about only having one template file so layout design is easy to change, which I loved the idea. But right away I thought I might have a problem somewhere, so I tried it out, and of course, I did.
What I'm doing is (mind you these tables and pages are just for testing):
I have a php file that lists all the songs i have in a table and links each song title to $PHP_SELF?id={$row['id']} which displays different information which works just fine by its self.
The problem is:
I have the index file with a table. On the left side I have "included" navigation.php,
and on the right side, I want to display my information.
I can get the if ($page){ function to work fine and "include" the other php file on the right side when the link is clicked. But the problem is when i click on the link in the "included" file on the right, it creates another variable called $id and refreshes the page with that variable, but the "included" file on the right isn't "included" anymore so it displays nothing. How do I get the file on the right to work properly when it is "included" within another file?
My navigation file.
<?php
$db = mysql_connect("localhost", "root", "pass");
mysql_select_db("database",$db) or die ('Did not select Database');
$query = "SELECT * FROM links";
$result = mysql_query($query);
echo "<table>";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr><td><a href=$PHP_SELF?page={$row['page']}.php>{$row['page']}</a></td></tr>";
}
echo"</table>";
?>
My categories file (the file on the right)
<?php
$db = mysql_connect("localhost", "root", "pass");
mysql_select_db("database",$db) or die ('Did not select Database');
if($id){
$query = "SELECT * FROM songs WHERE id=$id ORDER BY genre, artist ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo "Artist: {$row['artist']}<br>";
echo "Song: {$row['song']}<br>";
echo "Album: {$row['album']}<br>";
echo "Genre: {$row['genre']}<br>";
echo "<a href=categories2.php>Back to Song List</a>";
} // end of while loop
} // end of if
else{
$query = "SELECT * FROM songs ORDER BY genre, artist ASC";
$result = mysql_query($query);
$prev_genre = ''; // Initialize to something that wouldn't match the DB data
$prev_artist = '';
echo "<table border=1 cellpadding=1 cellspacing=0>"; // echo before while so it only writes once
while ($row = mysql_fetch_assoc($result)) {
if ($prev_genre != $row['genre']) {
echo "<tr><td bgcolor=blue><font color=white><b>{$row['genre']}||</b></font></td></tr>"; // Display name once per genre
$prev_genre = $row['genre']; // Set to current genre
} // end of if
if ($prev_artist != $row['artist']) {
echo "<tr><td bgcolor=lightblue> ||{$row['artist']}</td></tr>"; // Display name once per artist
$prev_artist = $row['artist']; // Set to current artist
} // end of if
echo "<tr><td bgcolor=white><a href=$PHP_SELF?id={$row['id']}><i> ||{$row['song']}</i></a></td></tr>";
}// end of while loop
echo "</table>"; // echo after while loop so it only writes once
}// end of else function
?>
and my index page:
<html>
<head>
<title></title>
</head>
<body bgcolor="#FFFFFF">
<table><tr><td>
<?
include 'navigation.php';
?>
</td>
<td>
<?
if ($page) {
include $page;
}else{
echo "no data to display yet";
}
?>
</td>
</tr>
</table>
</body>
</html>
hope you understand what i'm asking...