Saturday, 1 September 2012

JSON ARRAY

var students = { "Maths" : [
{ "Name" : "Amit", // First element
"Marks" : 67,
"age" : 23 },
{
"Name" : "Sandeep", // Second element
"Marks" : 65,
"age" : 21 }
],
"Science" : [
{ "Name" : "Shaili", // First Element
"Marks" : 56,
"age" : 27 },
{ "Name" : "Santosh", // Second Element
"Marks" : 78,
"age" : 41 }
]
}
// Printing all array values
var i=0
document.writeln("<table border='1'><tr>");
for(i=0;i<students.Maths.length;i++)
{
document.writeln("<td>");
document.writeln("<table border='0' width=100 >");
document.writeln("<tr><td><B>Name</B></td><td width=50>"+students.Maths[i].Name+"</td></tr>");
document.writeln("<tr><td><B>Marks</B></td><td width=50>"+students.Maths[i].Marks +"</td></tr>");
document.writeln("<tr><td><B>Age</B></td><td width=50>"+students.Maths[i].age +"</td></tr>");
document.writeln("</table>");
document.writeln("</td>");
}
for(i=0;i<students.Science.length;i++)
{
document.writeln("<td>");
document.writeln("<table border='0' width=100 >");
document.writeln("<tr><td><B>Name</B></td><td width=50>"+students.Science[i].Name+"</td></tr>");
document.writeln("<tr><td><B>Marks</B></td><td width=50>"+students.Science[i].Marks +"</td></tr>");
document.writeln("<tr><td><B>Age</B></td><td width=50>"+students.Science[i].age +"</td></tr>");
document.writeln("</table>");
document.writeln("</td>");
}
document.writeln("</tr></table>"); 

Thursday, 23 August 2012

Magento Integration: Session Login

Magento Integration: Session Login

Monday, 13 August 2012

how to create Json object


<script type="text/javascript">
$('form').live('submit',

function(){
     var p = document.forms['propertyform'];//form id

    var JSONObject = new Object;
    JSONObject.tire = new Array;
    var divcount = $("#TextBoxesGroup > div").size();//counting no of value
    for(var i=0; i<divcount; i++)
    {
        JSONObject.tire[i] = new Object
        JSONObject.tire[i].website_id = '0';
        JSONObject.tire[i].cust_group = '3200';
        JSONObject.tire[i].price_qty = p['price_qty'][i].value;// getting value from input box
JSONObject.tire[i].price = p['price_j'][i].value;// getting value from input box
    }

    JSONstring = JSON.stringify(JSONObject);

        var input = $("<input>").attr("type", "hidden").attr("name", "json").val(JSONstring);
        $('#propertyform').append($(input));//appending to an submit action
return true;


});
</script>
html file

<div id="TextBoxesGroup">
                        <label>Qty</label><label>price</label>
                            <div id="TextBoxDiv0" style="display:none">
                                    <input type="hidden" id="price_qty" name="price_qty" value="0">
                                    <input type="hidden" id="price_j" name="price_j" value="0" >
                                    <a class="removethis" data-action="TextBoxDiv1" count="0">remove</a>
                            </div>
                            <div id="TextBoxDiv1">
                                    <input type="text" id="price_qty" name="price_qty" count="1">
                                    <input type="text" id="price_j" name="price_j" >
                                    <a class="removethis" data-action="TextBoxDiv1" count="1">remove</a>
                             </div>
      </div>

php file


             $decoded = json_decode($_POST['json'],true);// to decode the json value in array formate



Tuesday, 10 July 2012

New Object-Oriented Features


The new OO features are too numerous to give a detailed description in this section. Chapter 3, “PHP 5 OO Language,” details each feature.The following list provides the main new features:

public/private/protectedaccess modifiers for methods and properties.Allows the use of common OO access modifiers to control access tomethods and properties:




class MyClass {
private $id = 18;
public function getId() {
return $this->id;
}
}


Unified constructor name__construct().
Instead of the constructor being the name of the class, it is now declared as __construct(), which makes it easier to shift classes inside class hierarchies:


class MyClass {
function __construct() {
print "Inside constructor";
}
}

Object destructor support by defining a __destructor() method.Allows defining a destructor function that runs when an object is destroyed:




class MyClass {
function __destruct() {
print ”Destroying object”;
}

}

Interfaces.

Gives the ability for a class to fulfill more than one is-a relationships. A class can inherit only from one class, but may implement as many interfaces as it wants:


interface Display {
function display();
}
class Circle implements Display {
function display() {
print "Displaying circle\n";
}
}




instance of operator.


Language-level support for is-a relationship checking. The PHP 4 is_a() function is now deprecated:




if ($obj instanceof Circle) {
print '$obj is a Circle';
}


Final methods.

The final keyword allows you to mark methods so that an inheriting class cannot overload them:


class MyClass {
final function getBaseClassName() {
return __CLASS__;
}
}


Final classes.

After declaring a class as final , it cannot be inherited. The following example would error out.


final class FinalClass {
}
class BogusClass extends FinalClass {
}


Explicit object cloning.

To clone an object, you must use the clone keyword. You may declare a __clone() method, which will be called during the clone process (after the properties have been copied from the original object):

Monday, 2 July 2012

Array Sorting Function


arsort — Sort an array in reverse order and maintain index association
asort — Sort an array and maintain index association
compact — Create array containing variables and their values
count — Count all elements in an array, or something in an object
current — Return the current element in an array
each — Return the current key and value pair from an array and advance the array cursor
end — Set the internal pointer of an array to its last element
extract — Import variables into the current symbol table from an array
in_array — Checks if a value exists in an array
key — Fetch a key from an array
krsort — Sort an array by key in reverse order
ksort — Sort an array by key
list — Assign variables as if they were an array
natcasesort — Sort an array using a case insensitive "natural order" algorithm
natsort — Sort an array using a "natural order" algorithm
next — Advance the internal array pointer of an array
pos — Alias of current
prev — Rewind the internal array pointer
range — Create an array containing a range of elements
reset — Set the internal pointer of an array to its first element
rsort — Sort an array in reverse order
shuffle — Shuffle an array
sizeof — Alias of count
sort — Sort an array
uasort — Sort an array with a user-defined comparison function and maintain index association
uksort — Sort an array by keys using a user-defined comparison function
usort — Sort an array by values using a user-defined comparison function

PHP MySQL Function

mysql_affected_rows — Get number of affected rows in previous MySQL operation
mysql_client_encoding — Returns the name of the character set
mysql_close — Close MySQL connection
mysql_connect — Open a connection to a MySQL Server
mysql_create_db — Create a MySQL database
mysql_data_seek — Move internal result pointer
mysql_db_name — Retrieves database name from the call to mysql_list_dbs
mysql_db_query — Selects a database and executes a query on it
mysql_drop_db — Drop (delete) a MySQL database
mysql_errno — Returns the numerical value of the error message from previous MySQL operation
mysql_error — Returns the text of the error message from previous MySQL operation
mysql_escape_string — Escapes a string for use in a mysql_query
mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_assoc — Fetch a result row as an associative array
mysql_fetch_field — Get column information from a result and return as an object
mysql_fetch_lengths — Get the length of each output in a result
mysql_fetch_object — Fetch a result row as an object
mysql_fetch_row — Get a result row as an enumerated array
mysql_field_flags — Get the flags associated with the specified field in a result
mysql_field_len — Returns the length of the specified field
mysql_field_name — Get the name of the specified field in a result
mysql_field_seek — Set result pointer to a specified field offset
mysql_field_table — Get name of the table the specified field is in
mysql_field_type — Get the type of the specified field in a result
mysql_free_result — Free result memory
mysql_get_client_info — Get MySQL client info
mysql_get_host_info — Get MySQL host info
mysql_get_proto_info — Get MySQL protocol info
mysql_get_server_info — Get MySQL server info
mysql_info — Get information about the most recent query
mysql_insert_id — Get the ID generated in the last query
mysql_list_dbs — List databases available on a MySQL server
mysql_list_fields — List MySQL table fields
mysql_list_processes — List MySQL processes
mysql_list_tables — List tables in a MySQL database
mysql_num_fields — Get number of fields in result
mysql_num_rows — Get number of rows in result
mysql_pconnect — Open a persistent connection to a MySQL server
mysql_ping — Ping a server connection or reconnect if there is no connection
mysql_query — Send a MySQL query
mysql_real_escape_string — Escapes special characters in a string for use in an SQL statement
mysql_result — Get result data
mysql_select_db — Select a MySQL database
mysql_set_charset — Sets the client character set
mysql_stat — Get current system status
mysql_tablename — Get table name of field
mysql_thread_id — Return the current thread ID
mysql_unbuffered_query — Send an SQL query to MySQL without fetching and buffering the result rows.

Monday, 25 June 2012

SQL Joins


1. Login in to the mysql client using the login name and password provided by your instructor (if
not already logged in).

2. View the existing databases that the MySQL Server is maintaining.

SHOW DATABASES;

3. Utilize the photo_album database.

USE photo_album;

---- If Need be, recreate the database and load the SQL data
in that will be used for this lab

CREATE DATABASE photo_album;
SOURCE /tmp/photo_album.sql;

4. Query the database to display the active primary customer (email, first and last name) and all
the associated active login names associated with that customer.

SELECT customers.email_customer, customers.fname,customers.lname, logins.login_name FROM customers, loginsWHERE customers.email_customer = logins.email_customer AND customers.active_customer = 'True' AND logins.active_login = 'True';

Saturday, 23 June 2012

SQL DML Commands


1. Login in to the mysql client using the login name and password provided by your instructor (if
not already logged in).

2. View the existing databases that the MySQL Server is maintaining.

SHOW DATABASES;

3. Utilize the photo_album database.

USE photo_album;
---- If Need be, recreate the database and load the SQL data
in that will be used for this lab
CREATE DATABASE photo_album;
SOURCE /tmp/photo_album.sql;

4. Search the customers records for the customer with the following e-mail address:
hollywood@truedog.com

SELECT * FROM customers WHERE email_customer ='hollywood@truedog.com'\G

5. Search the logins records for logins associated with the customer identified in step 4.

SELECT * FROM logins WHERE email_customer ='hollywood@truedog.com';

6. In the customers table, update the customers e-mail address, identified in step 4, to
howleewood@truedog.com.

UPDATE customers SET email_customer = 'howleewood@truedog.com'
WHERE email_customer = 'hollywood@truedog.com';

7. Review the customers records to see if the change (from step 6) took place. If the update did
not take place, reissue the statement in step 6 to ensure the change takes place?

SELECT * FROM customers WHERE email_customer ='howleewood@truedog.com'\G

8. Review the logins table to see if the e-mails associated with the customer in step 6 were also
changed. If the e-mail associated with that customer were also changed in the logins table,
why?

SELECT * FROM logins WHERE email_customer ='howleewood@truedog.com'\G

Thursday, 21 June 2012

SQL Expressions


1. Login in to the mysql client using the login name and password provided by your instructor (if
not already logged in).

2. View the existing databases that the MySQL Server is maintaining.

SHOW DATABASES;

3. Utilize the photo_album database.

USE photo_album;

---- If Need be, recreate the database and load the SQL data in that will be used for this lab

CREATE DATABASE photo_album;
SOURCE /tmp/photo_album.sql;

4. Calculate how many days ago each person logged into the photo_album system. Note:
Difference in dates are returned in microseconds when directly subtracted from each other.

SELECT login_name, ROUND((NOW() - last_login)/24/60/60/60)
FROM logins;

5. List the actual day name (Monday, Tuesday, etc.) for the last logins to determine if there is a
trend in the day of the week for the last time a person logged into the photo_album system.

SELECT login_name, DAYNAME(last_login) FROM logins;

6. Modify the statement above by having the output show 'Weekend' for Saturday and Sunday, and
'Weekday' for every other day.

SELECT login_name, IF(DAYNAME(last_login)
IN('Saturday','Sunday'),'Weekend','Weekday') FROM logins;

7. Show the expiration dates (term_date) for the customers with the first name Granny and
Yogi, without using two where statements.

SELECT f_name, term_date from customers WHERE fname
IN('Granny','Yogi');