[program-l] Generating Multiple Webpages in one Webpage with PHP

  • From: Edgar Lozano <1419goku@xxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Mon, 29 Oct 2012 06:58:41 -0500

Hi,
I believe that I've inquired about this topic once, but I have not
revisited the specific script to modify it.
But if someone could please answer this e-mail again, I would greatly
appreciate it.
Anyway, my main goal is to ccreate a PHP page that will generate
different webpages according to ID entries in a MySQL database.
I've completed the majority of the script, but my main issue is
displaying the title for the main page itself!
For example, when generating webpages for existing entries in a MySQL
table, the script successfully displays a title for its corresponding
ID, but for some reason, it won't display a title for the main page
itself, as I tried to do with conditional statements.
Code is as follows:

<?php
$servername = "server";
$serveruser = "user";
$serverpassword = "password";
$connect = mysql_connect($servername, $serveruser, $serverpassword);
$db = mysql_select_db("database", $connect);
?>
<!DOCTYPE HTML>
<html lang='en-US'>
<head>
<?php
$query = mysql_query("SELECT * FROM table
 WHERE ID='$_GET[id]'");
while($row = mysql_fetch_array($query))
{
if(!isset($_GET['id']))
{
echo "<title>Archives</title>";
}
else
{
if($_GET['id'] == $row['ID'])
{
echo "<title>".$row['title']." - RealRandomRadio Archives</title>";
}
}
}
?>
<link rel='stylesheet' type='text/css' href='css.css' />
</head>
<body>
<div id='wrapper'>
<?php include("header.php"); ?>
<div id='main_section'>
<aside id='main_aside'>
<p>
Content for main page goes here.
</p>
<?php
$query = mysql_query("SELECT * FROM table
 WHERE ID='$_GET[id]'");
while($row = mysql_fetch_array($query))
{
if($_GET['id'] == $row['ID'])
{
$sql = "UPDATE table
SET `listeners` = `listeners`+1
WHERE ID='" . $row['ID'] . "'";
mysql_query($sql);
echo
"
<p>
You are currently listening to ".$row['title'].".<br>
A short description is as follows:<br>
".$row['description']."<br>
We hope you enjoy this episode.<br>
So far, ".$row['listeners']." have listened to this episode.
</p>
<script type='text/javascript' src='playsound.js' />
</script>
<embed src='" . $row['url'] . "' autostart=true enablejavascript=true
id='mc1' />
";
}
}
$query = mysql_query("SELECT * FROM table
while($row = mysql_fetch_array($query))
{
$id = $row['ID'];
$title = $row['title'];
$description = $row['description'];
$date = $row['date'];
$url = $row['url'];
$listeners = $row['listeners'];
echo
"
<h2><a 
href='http://www.realrandomradio.com/archives/index.php?id=".$id.";'>".$title."</a></h2>
<p>
".$date."<br>
".$description."</p>
";
}
?>
</div>
<?php include("footer.php"); ?>
</div>
</body>
</html>

That is my entire code for an archives page that I'm creating for my website.
I believe someone mentioned me using MySQLI instead of MySQL, but I
want to find out the issue with this script first, and then I'll
switch to better programming practices.
I really appreciate all the help that I get.

-- 
Thanks for reading.
Have a good day.
If you ever get the chance, go to http://www.realrandomradio.com and
check us out.
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: