I have been posting some web-dev help, PHP scripts and CSS styles codes on my Sixth Sense India blog. Earlier, I use to put PHP codes under <blockquote> </blockquote> tags, but found that it does not look imperessive and is not easy to read or copy from the post page. Recently, I came to know about a way to post Php Source code on to blog post. You can use a plugin SyntaxHighlighter Evolved and publish your Code snippets like this
//Put your Code Here
echo “Hello World”;
It will render like as its shown here below
//Put your Code Here
echo "Hello World";
//PHP Random HTML Script
$random_number = rand(1, 2); // number of banners to shuffle
$random_banner = '<a href="http://shaadiwala.com" target="_new"><img class="wp-image-1232" src="http://shaadiwala.com/images/creatives/shaadiwala_banner_200x200.jpg" alt="" border="0"></a>';
$random_banner = '<a href="http://shaadiwala.com" target="_new"><img src="http://shaadiwala.com/images/creatives/shaadiwala_box_200x200.jpg" alt="" border="0"></a>;';
// print random banner on web page
This very useful PHP script for every web-developer to keep in his Script pile.
The benefit of choosing PHP as a web platform is its utility in dynamic and database driven web applications. It is fairly easy in PHP script to make a connection to MySQL database.
$connection = mysql_connect("DataBase-Host", "DataBase-user","Password-of-databse") OR die('Error connecting to mysql'); //means do not execute code any further.
$dbname = 'databasename';
There is one more better way to go with above code statement.
Good practice is to make a single file which can be called as and when it is required.
like you can save a file with a name e.g. connection.php with following code in it and can include it in any file to have a Database connection.
Here we will assign values to variables and it can be handy when you start coding more and more. You do not have to type data base connection script code every time just use include function and code will become part of that script.
e.g. <?php include “config.php”;?>
You can edit parameters to your own database values.
Save this file as config.php
// This is an example of connection.php
$dbhost = 'localhost';
// HOST OF DATABSE generally its localhost
$dbuser = 'root';
// USER OF DATABASE
$dbpass = 'password';
// PASSWORD of the Database User account
$dbname = 'learnphp';
// Name of Databse
$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die ('Error connecting to mysql');
Ok you wanna learn PHP. Who knows you might be running next big thing. What ever! lets start first lesson. Your first code in PHP scripting language. I would advise you to learn a bit of HTML before you jump into PHP coding thing.
Like HTML, PHP also lives in tags known as open and close tags. <? is the open or start tags and ?> is close tags. Every PHP code stats with open tags and ends with close tags. In PHP 5 version coders are more inclined to use <?php open tags rather than <?
There are some really simple script commands in PHP like PRINT, ECHO, SET, GET, POST, FOR, WHILE etc. Just like ordering someone to do a certain job for you. Yeah! just like that. 🙂
Before you begin coding PHP you need to download a few Freeware softwares from Continue reading “Learn PHP : Lesson 1 – Get it Easy”