Thursday, October 25, 2012

Php Tutorials Working with Conditions.

    Working with Php is not as difficult as you might think. One way to think of it would be like making making a list of things to do. And with this list you may want to add more list. Now for a start you have two list. But one list you only want to show to you. And the second list you want everyone else to see. This would be called a Condition. A Conditional statement would be needed to only show your list to you, and only show everyone else the second list. This is what we call a Conditional Statement. Let us look at this example.

IF list one = you;
    {then show list 1} ELSE {show list 2} now this being our Condition.

Now lets see how it works with Php. We now have Objects that we need to assign a Variable to so Php knows what they are. Our Object Variables would be "$list_one" "$list_two" "$you" and "$everyone" . Php makes it simple because you can name your Variables what they represent and Php will store these values temporarily or permanently within the program where you may need them.

$you = 'Bob';
$everyone = 'everyone else !';
$list_one = 'This is your list !';
$list_two = 'This is everyone else's list !';  
IF $you == 'Bob';
    {ECHO "$list_one";} ELSE {ECHO "$list_two";}

Now for each Conditional Check we must have a Operator--
this would be our "= (equals to)"  "==(does equal)" and "!= (does not equal)".
In this case You = Bob so it will show only Your List_one.
You can reverse this also to where your Condition checks if you Does Not Equal or != Then show everyone elses list_two first. 

Wednesday, October 10, 2012

Php Request Handlers Ajax

This is similar to how facebook uses ajax. It is the closest i have got.
This is the ajax script. place it in head section or create a js. page for it and include it. index.php.

<script language="javascript"  type="text/javascript">
function doHttpRequest() {  // This function does the AJAX request"GET", "", true);
  http.onreadystatechange = getHttpRes;
function doHttpRequest2() {  // This function does the AJAX request"GET", ""+document.getElementById('txt1').value, true);
  http.onreadystatechange = getHttpRes;
function getHttpRes() {
  if (http.readyState == 4) {
        res = http.responseText;  // These following lines get the response and update the page
        document.getElementById('div1').innerHTML = res;
function getXHTTP() {
  var xhttp;
   try {   // The following "try" blocks get the XMLHTTP object for various browsers…
          xhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
                xhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e2) {
          // This block handles Mozilla/Firefox browsers...
          try {
                xhttp = new XMLHttpRequest();
          } catch (e3) {
                xhttp = false;
  return xhttp; // Return the XMLHTTP object
var http = getXHTTP(); // This executes when the page first loads.
<body align="center">
<input align="center" type="button" value="Press for AJAX" name="btn" onClick="doHttpRequest();" >
<div align="center" id="div1"> <h3> Dynamic AJAX will be displayed here. </h3>  </div>   <!---this will be the dynamic div that does the majic. //--->

This is the form show method Page. formdata.php.

<h3 align="center">Here is an HTML Form, enter data, click submit…</h3>
<Form align="center" name="myform">
          Type text: <input align="center" type="text" size="15" id="txt1" >
          <input align="center" type="button" value="Press to submit form" onClick="doHttpRequest2();">

And this is the either recieve data request page or send data action page without page refresh. formrequest.php.

<h3 align="center">Here is the Form field text: <?php echo $_GET["txt1"]; ?></h3><br />
<p>Welcome to the most amazing site !</p>
Facebook uses everything but Php runs all the functions, classes, views, and validation and database scripts. Ajax Push and Pulls most of the Php page request, and handles all their Url Request, and Jquery handles the chat scrollers and C++ is used for parsing xhtml from outside sources, for your video-chat downloaded chat and, and lastly for the apps and game integration and application sharing API'S for all sites outside sourcing. .
You will want to sanitize the Txt1 Data when it gets retrieved by your action page !
Play with this for a while. I have already created a wall posting script identical to facebooks that im using in a business portal using this altered with the same req methods.. Enjoy. 

Thursday, October 4, 2012

Php Functions !

Below is a simple Function set up for Users. You can change this to whatever you like. The idea here is to get used to how they work. And later we will combine them into Classes.

function myFunction()        //WE NAME OUR FUNCTION// CAN BE      " select_user() "  //
  global $database_name, $link;     //THESE CAN BE BROUGHT IN BY INCLUDES WITHOUT//
  $retArr = array();

  mysql_select_db($database_name, $link);   //THIS CAN BE BROUGHT IN WITH INCLUDES ALSO/
  $query_queryLookup = "SELECT userId, userName, userFirst, userLast, userPw FROM users WHERE userId = '$id'";                    //AND HERE YOU MAY WANT TO USE $_SESSIONUSERID ETC///
  $queryLookup = mysql_query($query_queryLookup, $link) or die(__FUNCTION__.': '.mysql_error($link));
  $row_queryLookup = mysql_fetch_assoc($queryLookup);
  $totalRows_queryLookup = mysql_num_rows($queryLookup);

    do {
    } while ($row_queryLookup = mysql_fetch_assoc($queryLookup));


  return $retArr;                                             //OUR RETURNED VARIABLE//

} // end function myFunction()