Hello, I'm Matt from Immortal GamerZ! Here to give you a simple short guide on a few simple php items
.
First of all lets start out with Variables. Lets explain what they are. Variables are basically a short term like $title to be very very easy to use more then once instead of typing it over again here are some examples:
Code:
<?php
$title='Immortal GamerZ';
$dbhost='DB Host';
$dbuser='DB User';
$dbpass='DB Pass';
$dbname='DB Name';
$user_table='User Table';
$link_table='Links Table';
$staff_table='Staff Table';
?>
Now here's the code to use these in a page
Code:
<?php
include("config.php");
?>
<html>
<head>
<title><?php echo $title; ?>
</title>
</head>
<body>
Hello Everyone!
</body>
</html>
Lets break this all down for you. You see <?php ?> is the normal php tags that you use in all php page's. Echo is what you use when you want to display text of some sort. $title; is what you use when you are displaying a variable or variable text.
Lets move onto MySQL Connection
.
Code:
<?php
$username="DB User";
$password="DB Pass";
$database="DB Name";
mysql_connect(DB Host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
?>
That is about as basic connecting to MySQL Through php can get!
Now lets move onto displaying data from a table:
Code:
<html>
<head>
<title>News System-Immortal GamerZ</title>
</head>
<body>
<?php
$username="DB User";
$password="DB Pass";
$database="DB Name";
mysql_connect(DB Host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM articles";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<?php
$i=0;
while ($i < $num) {
$title=mysql_result($result,$i,"title");
$author=mysql_result($result,$i,"Author");
$body=mysql_result($result,$i,"body");
?>
<center><div style="width:420px; margin-bottom:30px;">
<?php echo $title; ?><br><hr>
<?php echo $body; ?><br><hr>
By:<?php echo $author; ?></div><br>
<?php
$i++;
}
?></center>
</body>
</html>
Okay that's all I have for ya today! I hope you enjoy it!