(The Website) Build PHP Database Driven Websites – Tutorial 3
Build the actual ecommerce website. Includes a free template with php scripts to publish the mysql data on the web.
Previously we had build the database structure and CMS for an online egames website and now we will work on the website itself.
- We are building a simple ecommerce dynamic website called games
- So far we have build a database structure and CMS with login page and add/delete/modify scripts.
- Download file 73.rar. “start” folder consist of the work done previously and “final” folder consist of the complete work done in this tutorial
Website
- Homepage will show the latest 10 games (index.php)
- Homepage links to a page with games details (product.php)
Download the 73.rar from this webpage; rename the folder “start” to “egames” and copy it to c:/wwwroot/inetpub.
Note:
- The start folder comes with a free web template, javascript validation, CMS and database structure for our egames website
- If you face any problems please check the config.php file
Lets start working ….. yo yo yo and ho ho ho…….. We have come to the main land!!! Anyways here goes something..
Open internet explorer type http://localhost/egames. Now you will see a whole ledged website like the one below.

I know the design is not relevant to an “egames” website, but I was in a hurry. If you guys want to load a relevant template click here to view the list of websites offering free and paid templates.
index.php
The aim is to display latest 10 games on the homepage . And to do that open up file index.php.
Add <? include("config.php");?> at the beginning of the page
Find <!— listing —> and type the following:
<?
$res=mysql_query("select * from product order by productid desc limit 0,10")or die(mysql_error());
while($row=mysql_fetch_array($res)) { $productid=$row["productid"];
echo "<h4>".$row["product"]."</h4><a href='product.php?productid=$productid'>".$row["bdesc"]."</a><hr><br>";}
?>
Can you see latest games………..noooo…………. of course you can’t cuz you haven’t added anything yet. To add the games go to the CMS that we had created in our previous tutorial by clicking on the “login” button in the green bar.
product.php
This is the easiestttt. Open product.php.
Find <!— listing —> and type the following:
<?
$productid=$_REQUEST["productid"];
$res=mysql_query("select * from product where productid='$productid'")or die(mysql_error());
$row=mysql_fetch_array($res); echo "<h4>".$row["product"]."</h4>".$row["bdesc"]."<br>".$row["ddesc"]."<hr><br>";
?>
Explanation
| Code | Explanation |
| index.php | |
<? include("config.php");?> |
Calls the config.php which has the code to connect the mysql database ‘egames’ |
$res=mysql_query("select * from product order |
Selects table “product” last ten entries |
while($row=mysql_fetch_array($res)) { |
Fetches data row by row from the table “product” |
echo "<h4>".$row["product"]."</h4> |
Finally displays the data on the webpage, the game title and brief description. Note: A link is given to ‘product.php’ page where product details will be shown using the ‘productid’ |
| product.php | |
<? include("config.php");?> |
Calls the config.php which has the code to connect the mysql database ‘egames’ |
$productid=$_REQUEST["productid"]; |
Extract the variable value from the URL <a href='product.php?productid=$productid'> |
$res=mysql_query("select * from product |
Selects table “product” data where productid matches |
$row=mysql_fetch_array($res); |
Fetches data row by row from the table “product”. Note we have not used “while” loop as there is only one entry for the particular “productid” |
$row=mysql_fetch_array($res); |
Finally displays the data on the webpage, the game title, brief description and detailed description. |
This page is fairly simple. Agreed?
But now lets imagine you want to the user to download games like .swf files++ and view images like .jpg and .gif. These are the extra features and require a few more lines of coding. If you guys are interested keep checking phpjavascript.com for new tutorials I will soon be covering such topics, and if you need anything extra lemme know!