Sunday, January 18, 2015

PHP basic page - learning to program php - lesson 01

Hello,

I started to program some php to make a web site with a database
To do so you need to install 2 programs.

For apache server and my sql server:
wampserver2.5-Apache-2.4.9-Mysql-5.6.17-php5.5.12-64b

To edit your mysql tables:
SQLyog-11.5.1-0.x64Community

Also, the web server will not start if SKYPE is open and use port 80
(or anything that use port 80 for that matter)

Installing WAMP will create in your C drive a folder like this: C:\wamp
Inside it, a web folder: C:\wamp\www
index.php is the starting file for the server
You should add a sub folder for a project you make like this:
C:\wamp\www\project02
Then in this folder create a index.php file with notepad2 (for the colors)

Inside index.php you can have a HTML part:

------------------------- index.php file start ----------------------------
<!DOCTYPE html>
<html:html>
<html:body>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><div align="center"> 

<title>my web site</title>

</head>

</html:body>
</html:html>
<html>
<body>

------------ comments start -------------

Now, since we are not newbs, we want to use inner html to build our page dynamically
So we insert a DIV zone called "zoneright"
Then a java script that will use inner html to update the content of that zone
Then a OD_flush et and flush to refresh the content (empty any buffer that was sent to your browser and apply change) without reloading the page

------------ comments end -------------

<?php
// $h is a variable to put html content
$h= "Nice web page that update dynamically";
// create a DIV zone with a name to use innrehtml later
$h.="<div id='zoneright'></div>";

// push the html content in the browser
echo $h;

// dynamic data to insert into the inner html zone "zoneright"
$h2 = "test 44";

// send a java script to the browser that will update the innerhtml zone for us
// syntax tip: before $h2 is a double quote " then a single quote '
// syntax tip: after $h2 is a single quote ' then a double quote "
echo '<script type="text/javascript">
  document.getElementById("zoneright").innerHTML = "'.$h2.'";
  </script>';
// empty all browser buffers to update the web page right now
ob_flush();
flush();
// wait 2 sec
sleep (2);

// new content
$h2 = "test 45";

// send another script to change inner html content for the new data in $h2
echo '<script type="text/javascript">
  document.getElementById("zoneright").innerHTML = "'.$h2.'";
  </script>';
// force brower to update right now again
ob_flush();
flush();

?>
-------------------- index.php file end ---------------------------

Now, save the index.php file
And load the local web site in your browser
http://localhost/project02

Now you learned to do some php, innerhtml and force a refresh on a page

Next, we will learn to use buttons to update the page content



7 comments:

  1. I am newbie of this PHP technology, this post helps me to know the introductory of PHP, Thanks for posting such a nice post.
    Regards,
    PHP Training Center in Chennai|PHP Course Chennai

    ReplyDelete
  2. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    Best Devops Training in pune
    Devops Training in Bangalore
    Microsoft azure training in Bangalore
    Power bi training in Chennai

    ReplyDelete
  3. This programm really helps in gaining some knowledge to improve our ideas or thoughts , i really love this blog.And its really useful.

    web designing training in chennai

    web designing training in tambaram

    digital marketing training in chennai

    ReplyDelete