Total Pageviews

Friday, February 24, 2012

Transform XML documents into XHTML with XSLT files

test.html

<form action = 'xml.php' method = 'post'>
    <h4>Search : </h4><input type = 'text' name = 'search' class='tb7'/><br/><br/>
   
               <input type = 'submit' value = 'Search' name='submit'/>
   
    </form>

xml.php

<?php
header('Content-type: text/xml');
include_once('config.php');

    if(isset($_POST['submit']))
    {
        $search=$_POST['search'];
        $query = "SELECT * FROM `member_details` where `Keywords` LIKE '%$search%'";
        $result = mysql_query($query);
        if(!$result )
        {
            die('Could not get data: ' . mysql_error());
        }       
        $xml_output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n";
        $xml_output .= "<?xml-stylesheet type=\"text/xsl\" href=\"xslt1.xsl\"?>";
        $xml_output .= "<dataset>\n";
        for($x = 0 ; $x < mysql_num_rows($result) ; $x++){
        $row = mysql_fetch_assoc($result);
        $xml_output .= "<entry>\n";
        $xml_output .= "<id>".$row['Id']."</id>\n";
        $xml_output .= "<name>".$row['Name']."</name>\n";
        $xml_output .= "<address>".$row['Address']."</address>\n";
        $xml_output .= "<postcode>".$row['Postcode']."</postcode>\n";
        $xml_output .= "<telephone>".$row['Telephone']."</telephone>\n";
        $xml_output .= "<opentime>".$row['OpenTime']."</opentime>\n";
        $xml_output .= "<restauranttype>".$row['ResType']."</restauranttype>\n";
        $xml_output .= "<licence>".$row['Licence']."</licence>\n";
        $xml_output .= "<keywords>".$row['Keywords']."</keywords>\n";
        $xml_output .= "<cuisine>".$row['Cuisine']."</cuisine>\n";
        $xml_output .= "</entry>\n";
           
        }
        $xml_output .= "</dataset>\n";    
        echo $xml_output;
       
    }

?>



xslt1.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

        <xsl:template match="/">
        <html>
        <body>
      
            <table border="0">
            <tr bgcolor="#9acd32">
                <th>Ref No.</th>
                <th>Name</th>
                <th>Telephone</th>
                <th>Full Details</th>
            </tr>
            <xsl:for-each select="dataset/entry">
            <tr>
                <td><xsl:value-of select="id"/></td>
                <td><xsl:value-of select="name"/></td>
                <td><xsl:value-of select="telephone"/></td>
                <td><xsl:variable name="vid" select="id"/><a href="fullviewXML.php?id={$vid}">full view</a></td>
              
            </tr>
            </xsl:for-each>
            </table>
        </body>
        </html>
        </xsl:template>
        </xsl:stylesheet>        

Friday, February 10, 2012

Inline background image change script for image

<img id="show_fare" src="images/btn_booking.png" onmouseover="this.src='images/btn_bookingo.png';" onmouseout="this.src='images/btn_booking.png';"/>


Thursday, February 9, 2012

MySQLi

MySQLi is referred to MySQL improved. It is an extension for PHP . This is released together with PHP5 and allows to use MySQL version 4.1.3 or newer.

It is object oriented
Supports to run more than one query at a time
More Secure

Connecting to MySQLi in Object Oriented way is as follow
<?php
$sql = new mysqli('hostname','username','password','databasename');
?>


Procedural way of connecting to database with MySQLi
<?php
$link = mysqli_connect('hostname','username','password','databasename');
?>


Wednesday, February 8, 2012

Sending Variables in URL


"page_a.php" or "page_a.html"

 // Send the variables name="ishara" and age=27 to the page_b.php
 <a href="page_b.php?name=ishara&age=27">Send variables</a> 

"page_b.php"

 <?php
  // Retrieve the URL variables (using PHP).
  $name = $_GET['name'];
  $age = $_GET['age'];
                // Display Values
  echo "Name: ".$name."  Age: ".$age;
 ?>


Output

Name: ishara Age: 27
 

File Uploading with PHP

 index.html
<form action="applyForJob.php" method="POST" enctype="multipart/form-data">
<input type="file" name="uploaded">
<input type="submit" name="Submit" value="Submit" />
</form>

applyForJob.php

<?php

    $target = "cv/";
    $target = $target . time(). basename($_FILES['uploaded']['name']);
  
     if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
    {
        echo "The file " . basename($_FILES['uploaded']['name']) . " has been uploaded";
       
    }
    else
    {
        if(isset($_POST['Submit']))
        echo "Sorry, there was a problem uploading your file.";
    }
?>

Monday, February 6, 2012

Database Naming Conventions


  1. All names used throughout the database should be in lowercase.
  2. Name parts are separated by underline not by a space. As underline is an alphanumeric character, database will be platform independent. Because sometimes space is not allowed.
  3. Numbers should not use for names
  4. (.) should not be used for names as separator, because (.) is used as field name in queries. Ex: tablename.columnname
  5. Must not use reserved words
  6. Should keep the names simple. Must not use long , complex names
  7. Database name should contain projectname
  8. Prefix should be company name or owner's name
  9. Ex: cmpn_invoice


Table Names

  1. Should contain name of entity followed by 3 letter  acronym. Acronym is created with table name. Ex: manufacturer_prd
  2. Also we can use prefix for table names same as database prefix for all the tables in that specific database  Ex: cecb_manufacturer_prd
  3. Should not use prefix like tbl_
  4. Should use simple short clear names for tables. Should not use doubtful names
  5. Should use singular names
  6. Group tables with same prefix as master table Eg: user_type, user_status
  7. Field Names
  8. For the primary key columns we can use id as name. For product_prd table id_prd is the primay key field name
  9. Foreign key can be named as idctg_prd. Here this foreign key belongs to product table product_prd. And it reffers to category table category_ctg
  10. Each column name should include 3 letters acronym of table name, Ex: name_prd
  11. date_ prefix shold use for date columns and is_ prefix should use for boolean type columns. Eg: date_expire, is_confirmed