Hello,
My cart class manages the shopping cart facility which almost every e-commerce site requires these days. This class does not do checkout with paypal, google check out or with any such similar services. But you can very easily manage the items being put into and taken away from the cart.
you can download the file from here:
http://nasaralla.googlecode.com/files/shopping_cart.php
And like in the following example can start managing your items:
___________________________________________________
//include the file
include("shopping_cart.php");
//start a session
session_start();
//initialize session variables
$_SESSION["item_list"] = array();
$_SESSION["item_total"] = 0;
//creating some items
$itm1 = new item("1","T-shirt","clothing","fcuk", "10.00", "cotton t-shirt", "image_url_not_available");
$itm2 = new item("2","Trouser","clothing","fcuk", "15.00", "Khaki trouser", "image_url_not_available");
$itm3 = new item("3","Cap","clothing","Next", "5.00", "all size cap", "image_url_not_available");
$itm4 = new item("4","jacket","formal","Austin reed", "100.00", "bond casino royal style", "image_url_not_available");
$itm5 = new item("5","Shoes","formal","Aldo", "50.00", "black naughty boy", "image_url_not_available");
//create your cart
$cart = new shopping_cart();
//add items to your cart
$cart->add_to_cart($itm1);
$cart->add_to_cart($itm2);
$cart->add_to_cart($itm3);
$cart->add_to_cart($itm4);
$cart->add_to_cart($itm5);
//print xml based status of the cart
$cart->print_cart_status();
//remove item in 3rd position (4th item)
$cart->remove_element(3);
//print xml based status of the cart
$cart->print_cart_status();
//end session
session_destroy();
___________________________________________________
And the xml output is like the following:
___________________________________________________
___________________________________________________
Blog Archive
Wednesday, 27 January 2010
Friday, 22 January 2010
PHP mail helper class
Hello,
todays post is about a very simple to use php helper class for mail sending.
The class is easy to use and can serve the purpose of multiple mail sending using one function call.
Remember you need to do all your validation yourself... until I build the php helper class for all possible sorts of required validations.
Simply get the mail class from http://nasaralla.googlecode.com/files/mail.php
________________________________________
//include the mail class in your code
include("mail.php");
//instantiate the Mailer class with the
$mail = new Mailer('receiver@example.com','sender@example.com','subject','message');
//or you can also instanciate with cc and Bcc
$mail = new Mailer('receiver@example.com','sender@example.com','subject','message','cc@example.com','bcc@example.com');
//then simple call the send mail function
$mail->send_mail();
//you can also send mail to a list of people
$mail = new Mailer('','sender@example.com','subject','message');
$array = new array('receiver1@example.com','receiver2@example.com','receiver3@example.com');
$mail->send_mail_list($array);
________________________________________
todays post is about a very simple to use php helper class for mail sending.
The class is easy to use and can serve the purpose of multiple mail sending using one function call.
Remember you need to do all your validation yourself... until I build the php helper class for all possible sorts of required validations.
Simply get the mail class from http://nasaralla.googlecode.com/files/mail.php
________________________________________
//include the mail class in your code
include("mail.php");
//instantiate the Mailer class with the
$mail = new Mailer('receiver@example.com','sender@example.com','subject','message');
//or you can also instanciate with cc and Bcc
$mail = new Mailer('receiver@example.com','sender@example.com','subject','message','cc@example.com','bcc@example.com');
//then simple call the send mail function
$mail->send_mail();
//you can also send mail to a list of people
$mail = new Mailer('','sender@example.com','subject','message');
$array = new array('receiver1@example.com','receiver2@example.com','receiver3@example.com');
$mail->send_mail_list($array);
________________________________________
Labels:
helper,
php,
php class,
php helper,
php mail,
php mail class,
php mail function
Thursday, 21 January 2010
Simple php Image Captcha
Hello all,
my next work is a very simple image captcha php class which simple prints a random image with string on it which is very useful for security purposes.
the file could be downloaded from http://nasaralla.googlecode.com/files/captcha.php
and the simple to use instructions are as follows:
_________________________________________
//include the class file
include("captcha.php");
//instanciate the class
$c = new Captcha();
//generate the random string with this function
$c->generateCaptcha();
//print the image
$c->printCaptcha();
_________________________________________
my next work is a very simple image captcha php class which simple prints a random image with string on it which is very useful for security purposes.
the file could be downloaded from http://nasaralla.googlecode.com/files/captcha.php
and the simple to use instructions are as follows:
_________________________________________
//include the class file
include("captcha.php");
//instanciate the class
$c = new Captcha();
//generate the random string with this function
$c->generateCaptcha();
//print the image
$c->printCaptcha();
_________________________________________
Labels:
captcha,
image captcha,
php,
php captcha function,
php class,
php helper
Simple php tabulation helper class
This class would allow you to grab your required 'view' of data from a given query by simply providing the query and changing your page number each time. The function does not provides any view it only has one print function which could be used for testing or could be overwritten to serve your purpose.
The helper class requires the database class in my previous post.
The tabulation class file could be downloaded from http://nasaralla.googlecode.com/files/tabulation.php
and you also need this database.php: http://nasaralla.googlecode.com/files/database.php
____________________________________________
//in your code you need to include tabulation.php as follows
include("tabulation.php");
//next you call the constructor and set the query only once and also the page limit
$tab = new Tabulation("select * from cutpriceh", 10);
//make sure you do not put a semi-colon (;) at the end
//then you need to set from which database (MySQL) you are bringing in the data
$tab->setDBParam("localhost","cutprice","root","");
//and you run the getResults function which given the page number would return the result set //as well as store the result set in a private variable ...
$results = $tab->getResults(3);
//Finally you could use the build in print table function to print your page of values
$tableIndex = array('Hotel','City');
$tab->printResults($tableIndex);
//the function takes in an array of database field names and prints only those fields
____________________________________________
The helper class requires the database class in my previous post.
The tabulation class file could be downloaded from http://nasaralla.googlecode.com/files/tabulation.php
and you also need this database.php: http://nasaralla.googlecode.com/files/database.php
____________________________________________
//in your code you need to include tabulation.php as follows
include("tabulation.php");
//next you call the constructor and set the query only once and also the page limit
$tab = new Tabulation("select * from cutpriceh", 10);
//make sure you do not put a semi-colon (;) at the end
//then you need to set from which database (MySQL) you are bringing in the data
$tab->setDBParam("localhost","cutprice","root","");
//and you run the getResults function which given the page number would return the result set //as well as store the result set in a private variable ...
$results = $tab->getResults(3);
//Finally you could use the build in print table function to print your page of values
$tableIndex = array('Hotel','City');
$tab->printResults($tableIndex);
//the function takes in an array of database field names and prints only those fields
____________________________________________
Simple php database helper function
the following PHP class has been written to simplify database usage in PHP and make it more of an object oriented way of performing tasks.
This function will also allow you to use mysql from php without having to bother about the php functions for SQL.
You can download the .php file from http://nasaralla.googlecode.com/files/database.php
The following example shows how you could use this file:
________________________________________
//Include the file
include("database.php");
//provide parameters for connecting to the MySQL server
//the functions needs to be provided with the host, database_name, username and password in //order
$db = new DBConnect('localhost', 'jobdb','root','');
$con = $db->setDB();
//then simply run any query using the following function
$result = $db->makeQuery("select * from candidate;");
//and finally terminate connection with server
$db->closeConnection($con);
________________________________________
Yes you are not totally independent of writing queries in this version which I hope to add in the future but this does gives you the flexibility of 'selecting' with a wider and more complex queries.
This function will also allow you to use mysql from php without having to bother about the php functions for SQL.
You can download the .php file from http://nasaralla.googlecode.com/files/database.php
The following example shows how you could use this file:
________________________________________
//Include the file
include("database.php");
//provide parameters for connecting to the MySQL server
//the functions needs to be provided with the host, database_name, username and password in //order
$db = new DBConnect('localhost', 'jobdb','root','');
$con = $db->setDB();
//then simply run any query using the following function
$result = $db->makeQuery("select * from candidate;");
//and finally terminate connection with server
$db->closeConnection($con);
________________________________________
Yes you are not totally independent of writing queries in this version which I hope to add in the future but this does gives you the flexibility of 'selecting' with a wider and more complex queries.
Subscribe to:
Posts (Atom)