Redesigning a wesbite I created into a single php file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amethyst80
Forum Newbie
Posts: 2
Joined: Wed Mar 24, 2010 3:34 pm

Redesigning a wesbite I created into a single php file

Post by amethyst80 »

I have to Redesign a very basic website created for Homework,

I have done the first part, which was to replace the list links to the 5 albums by a form with a drop-down selection and a Submit button.

the bit I am stuck is that I have to Replace the 5 HTML files for the 5 albums with a single PHP file. I have looked at php code to try and do this, but I am not finding any success for what I need, so if anyone can point me in the right direction, or links to good php tutorials thanks :D

here is one of the html albums files

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
 <head>
  <link rel="stylesheet" type="text/css" href="pop_albums.css"/>
    <title>Busta_Rhymes</title>
 </head>
 
 <body>
 <div id="content">
  <ul id="navigation">
    <li><a href="index.html">home</a></li>
    <li><a href="Madonna.html">American Life</a></li>
    <li><a href="Metallica.html">St. Anger</a></li>
    <li><a href="Otep.html">Sevas Tra</a></li>
    <li><a href="Patti_Smith.html">Easter</a></li>
    <li><a href="Busta_Rhymes.html">The Big Bang</a></li>
   </ul>
   
   <div id="pic">
    <img src="images/busta_rhymes_the_big_bang.jpg" />
   </div>
 
 
  <h2 id="header">Busta Rhymes - The Big Bang</h2>
  
     <div id="tracks">
       <ol>
        <li>Get You Some - (featuring Marsha From Floetry/Q-Tip)- 3.06</li>
        <li>Touch It - 2.45 </li>
        <li>How We Do It Over Here - 3.22</li>
        <li>New York S*** - 6.14</li>
        <li>Been Through The Storm - 1.43</li>
        <li>In the Ghetto - 4.42</li>
        <li>Cocaina - 5.06</li>
        <li>You Can't Hold the Torch - 2.09</li>
        <li>Goldmine - 7.43</li>
        <li>I love My B****- 5.52</li> 
        <li>Don't Get Carried Away - 2.09</li>
        <li>They're Out to Get Me - 7.43</li>
        <li>Get Down- 5.52</li> 
        <li>I'll Do It All - 7.43</li>
        <li>Legend of the Fall Offs 5.52</li> 
         </ol>
     </div>  
   
 </body>
</html>   
 
 
 
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Redesigning a wesbite I created into a single php file

Post by cpetercarter »

It would be easier to make suggestions if you could explain why you want to replace the html files with something written in php. If the existing files do what you want, why fix them? But if they don't do what you want, what do you want different?
amethyst80
Forum Newbie
Posts: 2
Joined: Wed Mar 24, 2010 3:34 pm

Re: Redesigning a wesbite I created into a single php file

Post by amethyst80 »

the website is fine but as it is, but I would like to see how to do it with a single php file, as I said if anyone can point in the right direction it would be great thanks:)
User avatar
Sofw_Arch_Dev
Forum Commoner
Posts: 60
Joined: Tue Mar 16, 2010 4:06 pm
Location: San Francisco, California, US

Re: Redesigning a wesbite I created into a single php file

Post by Sofw_Arch_Dev »

Since you're in school, you should have access to a library. Maybe you can find something like this. Sounds like you could use an introduction with a book at your side for reference.
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: Redesigning a wesbite I created into a single php file

Post by Sephern »

Probably worth looking into $_GET, to start with, as well as basic programming stuff like variables, conditional statements, and ways to output the data (echo).
Phinisher
Forum Newbie
Posts: 2
Joined: Wed Mar 24, 2010 5:49 pm

Re: Redesigning a wesbite I created into a single php file

Post by Phinisher »

Just pass and get the variable or id of the page through the url.

This may not be the "accepted" way, but it is what I have used before to accomplish what you are talking about.

Code: Select all

 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="pop_albums.css"/>
<title>Busta_Rhymes</title>
</head>
<?php
//This pulls the page id from the URL and passes it the the $page variable
if (isset($_GET['page'])) {
$page = $_GET['page'];
 
if ( $page == 1 ) {
    $pic_url = 'images/busta_rhymes_the_big_bang.jpg'; //Your picture url is passed to this variable
        $title = 'Busta Rhymes - The Big Bang';  //Title of this page
        $track[] = 'Title of Track 1'; // For each track just add another one, they will automatically store in the next slot for you.
        $track[] = 'Title of Track 2';
}
else if ( $page == 2 ) {
    $pic_url = 'images/yougettheidea.jpg'; //Your picture url is passed to this variable
        $title = 'New Tunes - Awesomness';  //Title of this page
        $track[] = 'Title of Track 1'; // For each track just add another one, they will automatically store in the next slot for you.
        $track[] = 'Title of Track 2';
} 
}
else {
//This will store WHAT to display in case of it being the home page and not having the variable
    $pic_url = 'images/busta_rhymes_the_big_bang.jpg'; //Your picture url is passed to this variable
        $title = 'Busta Rhymes - The Big Bang';  //Title of this page
        $track[] = 'Title of Track 1'; // For each track just add another one, they will automatically store in the next slot for you.
        $track[] = 'Title of Track 2';
}
?>
 
<body>
<div id="content">
<ul id="navigation">
<li><a href="index.php">home</a></li>
<li><a href="index.php?page=1">American Life</a></li>
<li><a href="index.php?page=2">St. Anger</a></li>
<li><a href="index.php?page=3">Sevas Tra</a></li>
<li><a href="index.php?page=4">Easter</a></li>
<li><a href="index.php?page=5">The Big Bang</a></li>
</ul>
 
<div id="pic">
<img src="<?php echo $pic_url; ?>" />
</div>
 
 
<h2 id="header"><?php echo $title; ?></h2>
 
<div id="tracks">
<ol>
<?php
foreach($track as $single)
{
echo "<li> ". $single. " </li>";
} 
?>
</ol>
</div>  
 
</body>
</html>   
 
I have no error handlers or anything in it... but this should give you a running start.
Post Reply