Web Development Network  |  Sites:    Capital Tutorials    Internet Marketing Books    Arcade Games
Depiction- Webmaster Resources
Stock Image


Contributors: SSD VPS in Europe  |  SEO Las Vegas |  EsqRank

Dental SEO Marketing  |  Best Las Vegas SEO Company  |  Currency Converter Live

Misc Links: Submit Tutorials (Earn $$) l Advertising l Privacy Policy | Site Map

Tutorials > PHP > Tutorial System

 

A walkthrough showing how to create a basic tutorial system.


Note: This tutorial walkthrough is intended for those who have a solid foundation of PHP basics.

We are going to use these variables for our MySQL database: Id, Title, avatar, date, description, user, and message.

1. Lets start off by creating our table. Go to your database, as I assume you already know how to create, and import this SQL.

Code:
------------------------------------------------------------------------
CREATE TABLE `tutorials` (`ID` tinyint(11) NOT NULL auto_increment,`title` text NOT NULL,`avatar` text NOT NULL,`date` date NOT NULL default '0000-00-00',`description` text NOT NULL,`user` text NOT NULL, `message` text NOT NULL,PRIMARY KEY (`ID`)) TYPE=MyISAM AUTO_INCREMENT=1 ;
------------------------------------------------------------------------

2. Now, we're going to enter in our tutorial into our table. In PHPmyAdmin (or whatever you use) insert a new row into your table, which we named tutorials. You don't need to add anything for the ID- it automatically increases the ID number by 1. After you finished entering in your data into the MySQL database, create a new file, using Dreamweaver or any other HTML editor. Name it dbconnect.php. Copy and paste this into your file; with of course adding in your information.

Code:
------------------------------------------------------------------------
<?$username = "yourusername";$password = "yourpassword";$host = "localhost";$database = "yourdatabase"; mysql_connect($host,$username,$password) or die("Error connecting to Database!" . mysql_error()); mysql_select_db($database) or die("Cannot select database!" . mysql_error());?>
------------------------------------------------------------------------

3. Now create a new file, in the same directory as the dbconnect.php file. Call it tutorials.php and put this in the file. However, you may have to change it to fit your needs.

Code:
------------------------------------------------------------------------
<?php
include ("dbconnect.php");
if (isset($ID)){$tuts="SELECT * from yourtable where ID='$ID'";$tuts2=mysql_query($tuts);while ($tuts3=mysql_fetch_array($tuts2))
{
echo "
<table width="100%" border="0" cellspacing="3" cellpadding="0"><tr><td><font color="#82A1FF" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>$tuts3[title]</b ><br><font color="#000000">By <b>$tuts3[user]</b><br><i> $tuts3[description]</i><br><br> $tuts3[message]<br><br></td></tr></table>
"; }}
else if(!isset($id)){$tut="SELECT * from yourtable";$tut2=mysql_query($tut);while
($tut3=mysql_fetch_array($tut2))
{
echo "
<font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><table width="250" border="0" cellspacing="3" cellpadding="0"><tr> <td width="42" height="42" ><div align="center"><a href='tutorials.php?ID=$tut3[ID]'><img src='$tut3[avatar]' border='0' alt='$tut3[title]' target='main'></a></div></td><td width="208"> <font color="#82A1FF" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong> $tut3[title]</strong><br><font color="#000000"><em>$tut3[date]</em>< br>By <strong>$tut3[user]</strong></font><br></font></td></ tr></table>
"; }}
?>

------------------------------------------------------------------------

Tutorial continues on page 2.


 
 

Affiliates

DNSandIP Photoshop Tutorials
Tutorial Man Wallpaper Stock  More

Resources