الثلاثاء، 2 أبريل 2013

Carbon Solar Cells

Though, we have discussed a lot about solar energy projects, but solar energy is not economically viable for our daily use because of increasingly expensive materials used in traditional solar cells made up of silicon, which is not available in abundance and hence very costly. Today, we will discuss about carbon solar cells and how to use them to built complete carbon solar cells?


Why Carbon ?

"Carbon has the potential to deliver high performance at a low cost," said study senior author Zhenan Bao, a professor of chemical engineering at Stanford. According to Professor Bao, in the future we can use solar cells,which are coated on the surface of buildings, on windows or on cars to generate electricity

How is it possible?

When we take elements into their nano scale, their properties start to change and  it happens with carbon too.Carbon nanotubes have great electrical conductivity. Stanford researches found that, they can use nanotechnology to build new type of solar cells by just using carbon.It consists of mainly three parts,
Two Electrodes made up of Carbon Nano tubes(graphene – sheets of carbon that are one atom thick –and single-walled carbon nanotubes that are 10,000 times narrower than a human hair) instead of expensive ITO(Indium Tin Oxide) and one Active Layer made of buckyballs(soccer ball-shaped molecules with carbon atoms at each vertex just 1 nano-meter of diameter).

Buckyball(C60):

It is a spherical football shaped fullerene molecule.
Formula: C60.

Graphene:

It is a substance composed of pure carbon, with atoms arranged in a regular hexagonal pattern similar to graphite, but in a one-atom thick sheet.

Carbon nanotubes:

Carbon nanotubes (CNTs) are allotropes of carbon with a cylindrical nanostructure.

Problems:

Basic problem with carbon solar cells is their efficiency which is only 1 Percent in comparison to silicon cells with 20 Percent efficiency.People working with this technology beleives that they can increase these cells efficiency significantly by implementing some minute changes during its manufacturing.

Advantages:
Their are many advantage of using carbon cells such as

Stanford Page: Build the first all carbon solar cell



Related:

Solar Projects

الثلاثاء، 12 فبراير 2013

Fifteen Puzzle Game


Developing game is always a fun and fifteen puzzle game is no different. In this game, puzzle can be solved by arranging tiles in a correct sequence or order.It is very interesting application and if you decide to develop this application in any respective language , it would be great learning experience for you.Before creating this puzzle , you should be aware of the fact that some time this puzzle is unsolvable(find out when and implement it accordingly).

Things to know:

1. Their is only one blank tile in the game.
2. Only one adjacent tile from a blank can move
3. That would also slide only to the blank position
Algorithm.
In one of the paper I read, i found one real time algorithm which use both divide and rule & Greedy Algorithm.
Download Source(available for c++ and perl)
Useful PDF:
A real time algorithm for n2-1 puzzle
Related Projects:
Computer Science Project


الجمعة، 11 يناير 2013

Beginners Hotel Management System in PHP

Project: Beginners Hotel Management System
Introduction: It is simple management system containing two sections:
1.User : User can find out whether their is any room available at any particular date
2.Admin: Admin can manage,update and create new bookings

Difficulty: Beginner
Estimated Time: 30 minutes
Languages: PHP and Mysql
Tools Required: Xampp, Notepad++

Download


Step1. Database creation
  • Open PHPMyAdmin using http://localhost/phpmyadmin in XAMPP 
  • Create Database: HOTEL 
  • Create Table:
  • CREATE TABLE IF NOT EXISTS `rooms_info` (
    `booking_id` int(11) NOT NULL AUTO_INCREMENT,
    `room_no` varchar(55) NOT NULL,
    `check_in` date NOT NULL,
    `check_out` date NOT NULL,
    `no_of_rooms` int(11) NOT NULL,
    PRIMARY KEY (`booking_id`),
    KEY `room_no` (`room_no`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
  • Insert some dummy data for a start
  • INSERT INTO `rooms_info` (`booking_id`, `room_no`, `check_in`, `check_out`, `no_of_rooms`) VALUES
    (1, '1', '2013-01-02', '2013-01-03', 3),
    (2, '2', '2013-01-03', '2013-01-04', 3),
    (3, '3', '2013-01-01', '2013-01-04', 2),
    (4, '4,5', '2013-01-04', '2013-01-05', 2),
    (5, '2,3,4', '2013-01-05', '2013-01-25', 2),
    (6, '5,6,8', '2013-02-07', '2013-02-28', 3),
    (7, '4,5,6', '2013-10-05', '2013-11-09', 3),
    (8, '2,3,4', '2013-03-05', '2013-03-08', 3),
    (9, '5,6,7', '2013-01-05', '2013-01-08', 3);
Step2. User Interface

Create index.php file where user can submit reservation form as well as gets update about reservation status
index.php
<?php
include('config.php');
if (isset($_GET['submit'])) {
/* Getting data from form submitted at index.php page */
$user_checkin_date = $_GET['checkin_date'];
$user_checkin_month = $_GET['checkin_month'];
$user_checkin_year = $_GET['checkin_year'];
$user_checkout_date = $_GET['checkout_date'];
$user_checkout_month = $_GET['checkout_month'];
$user_checkout_year = $_GET['checkout_year'];
$persons = $_GET['persons']; // this variable will be used when we scale up this application
$rooms = $_GET['rooms'];
/* End of collecting data */

//Check for any invalid submissions, you should apply as much validation as possible
if ($user_checkin_month == 2 || $user_checkin_month == 4 || $user_checkin_month == 6 || $user_checkin_month == 9 || $user_checkin_month == 11 || $user_checkout_month == 2 || $user_checkout_month == 4 || $user_checkout_month == 6 || $user_checkout_month == 9 || $user_checkout_month == 11) {
if ($user_checkin_date >= 31 || $user_checkout_date >= 31) {
$error = 1;
$error_type[] = "For month $user_checkin_month 31st is invalid Date";
} else if ($user_checkin_month == 2 || $user_checkout_month == 2) {
if ($user_checkin_date >= 28 || $user_checkout_date >= 28) {
$error = 1;
$error_type[] = 'Feb Date Error';
}
} else {
$error = 0;
}
} else {
$error = 0;
}
if ($user_checkin_date >= $user_checkout_date) {

$error = 1;
$error_type[] = "Check out date can't be equal or lesser than check in date , please try again!!";
}

// converting date into yyyy-mm-dd format
$user_checkin_date = "$user_checkin_year" . "-" . "$user_checkin_month" . "-" . "$user_checkin_date";
$user_checkout_date = "$user_checkout_year" . "-" . "$user_checkout_month" . "-" . "$user_checkout_date";
// info convert into unix timestamp
$user_checkin_date = strtotime($user_checkin_date);
$user_checkout_date = strtotime($user_checkout_date);
global $total_rooms_available;
$total_rooms_available = 10;
while ($row = mysql_fetch_array($result)) {
$check_in = $row['check_in'];
$check_out = $row['check_out'];
$no_of_rooms = $row['no_of_rooms'];
$check_in = strtotime($check_in);
$check_out = strtotime($check_out);
// test for availability with check in and check out date
if ($check_in <= $user_checkin_date && $user_checkin_date < $check_out) {

$room_available = 0;
$total_rooms_available = $total_rooms_available - $no_of_rooms;
} // end of if check in loop
else {
if ($check_in < $user_checkout_date && $user_checkout_date <= $check_out) {
$room_available = 0;
$total_rooms_available = $total_rooms_available - $no_of_rooms;
} // end of if checkout loop
else {
$room_available = 1;
} // end of else check out loop
}
}
}// end of if submit button has pressed
?>
<h3>Reservation:</h3>
<form action="index.php" id="reservation-form">
<fieldset>
<div class="field"><label>Check In:</label><select class="select1" name="checkin_date"><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option></select><select class="select1" name="checkin_month"><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option></select><select class="select2" name="checkin_year"><option>2013</option><option>2014</option><option>2015</option><option>2016</option></select></div>
<div class="field"><label>Check Out:</label><select class="select1" name="checkout_date"><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option></select><select class="select1" name="checkout_month"><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option></select><select class="select2" name="checkout_year"><option>2013</option><option>2014</option><option>2015</option><option>2016</option></select></div>
<div class="field"><label>Persons:</label> <select class="select1" name="persons"><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option></select> </div>
<div class="field"><label>Rooms:</label><select class="select1" name="rooms"><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option></select></div>
<div class="button"><span><span><input type="submit" name="submit" value="Check Availability" /></span></span></div>
</fieldset>
</form>
<?php if (isset($_GET['submit'])) { ?>

<h2>Reservation Update!</h2>
<?php
if ($error) {
foreach ($error_type as $value) {
echo"$value<br />";
}
} else {
if ($rooms < $room_available && $room_available != 0) {
echo "Only $room_available room is available instead of $rooms rooms required by you";
} else {
echo "$total_rooms_available rooms are available , call 0000000(hotel number) to book now";
}
}// end of else about check in date lesser than check out date
} // end of if isset get submit loop
?>

 Step3. Admin Section 
In admin section, we will need mainly three files and one class, first admin/index.php and second admin/login_success.php third admin/Logout.php and fourth one is third party class tc_calendar(optional) which helps us to show javascript calendar.

  • Create new folder Admin
  • Create index file and paste php source shown below
  • // user name and password for admin, preferred way is to create database user table inside database
    $username = "hotel";
    $password = "123456";
    if (isset($_POST['Submit'])) {
    // username and password sent from form
    $myusername = $_POST['myusername'];
    $mypassword = $_POST['mypassword'];

    // To protect MySQL injection
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    } // end of isset post submit
    ?>


    <p><br /><br />Welcome to Administrator Page of <a href="http://hotel.url">Hotel!</a></p>
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <form name="form1" method="post" action="./">
    <td>
    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
    <tr>
    <td colspan="3"><strong>Member Login </strong></td>
    </tr>
    <tr>
    <td width="78">Username</td>
    <td width="6">:</td>
    <td width="294"><input name="myusername" type="text" id="myusername"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td>:</td>
    <td><input name="mypassword" type="password" id="mypassword"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Login"></td>
    </tr>
    <?php
    if (isset($_POST['Submit'])) {
    echo"<tr><td COLSPAN=3>";
    // If result matched $myusername and $mypassword, table row must be 1 row
    if ($myusername == $username && $mypassword == $password) {

    // Register $myusername, $mypassword and redirect to file "login_success.php"
    $_SESSION['username'] = $username;

    header("location:login_success.php");
    } else {
    echo "<p style=\"background-color:#FFE0FF\">Wrong Username or Password ! <a href=\"../Admin\">Login Again</a></p>";
    }
    echo"</td></tr>";
    }
    ?>
    </table>
    </td>
    </form>
    </tr>
    </table>
  • login_sucess.php
  • <?php
    ############### Code
    // Check if session is not registered, redirect back to main page.
    // Put this code in first line of web page.

    session_start();
    if (!isset($_SESSION["username"])) {
    echo"Invalid username and password<br />";
    echo"Please try again";
    echo"<a href=\"./index.php\">Click Here</a>";
    header("location:index.php");
    }
    include("../config.php");
    ?>
    <script language="javascript" src="calendar.js"></script>

    <h1> Admin Page </h1>
    <p><br /><br />Welcome to Administrator Page of <a href="http://hotel.url">Hotel!</a></p>
    <?php
    if (isset($_SESSION["username"])) {
    echo"<a href=\"./Logout.php\">Log Out!</a>";
    }

    if (isset($_POST['submit'])) {

    $booking_1 = $_POST['booking1'];
    $room_no_1 = $_POST['room_no1'];
    $check_in_1 = $_POST['check_in1'];
    $check_out_1 = $_POST['check_out1'];
    $no_of_rooms_1 = $_POST['no_of_rooms1'];
    $result = mysql_query("UPDATE `hotel`.`rooms_info` SET `room_no` = '$room_no_1',
    `check_in` = '$check_in_1',
    `check_out` = '$check_out_1',
    `no_of_rooms` = '$no_of_rooms_1' WHERE `rooms_info`.`booking_id` = $booking_1;")
    or die(mysql_error());


    $booking_2 = $_POST['booking2'];
    $room_no_2 = $_POST['room_no2'];
    $check_in_2 = $_POST['check_in2'];
    $check_out_2 = $_POST['check_out2'];
    $no_of_rooms_2 = $_POST['no_of_rooms2'];
    $result = mysql_query("UPDATE `hotel`.`rooms_info` SET `room_no` = '$room_no_2',
    `check_in` = '$check_in_2',
    `check_out` = '$check_out_2',
    `no_of_rooms` = '$no_of_rooms_2' WHERE `rooms_info`.`booking_id` = $booking_2;")
    or die(mysql_error());


    $booking_3 = $_POST['booking3'];
    $room_no_3 = $_POST['room_no3'];
    $check_in_3 = $_POST['check_in3'];
    $check_out_3 = $_POST['check_out3'];
    $no_of_rooms_3 = $_POST['no_of_rooms3'];
    $result = mysql_query("UPDATE `hotel`.`rooms_info` SET `room_no` = '$room_no_3',
    `check_in` = '$check_in_3',
    `check_out` = '$check_out_3',
    `no_of_rooms` = '$no_of_rooms_3' WHERE `rooms_info`.`booking_id` = $booking_3;")
    or die(mysql_error());


    $booking_4 = $_POST['booking4'];
    $room_no_4 = $_POST['room_no4'];
    $check_in_4 = $_POST['check_in4'];
    $check_out_4 = $_POST['check_out4'];
    $no_of_rooms_4 = $_POST['no_of_rooms4'];
    $result = mysql_query("UPDATE `hotel`.`rooms_info` SET `room_no` = '$room_no_4',
    `check_in` = '$check_in_4',
    `check_out` = '$check_out_4',
    `no_of_rooms` = '$no_of_rooms_4' WHERE `rooms_info`.`booking_id` = $booking_4;")
    or die(mysql_error());


    $booking_5 = $_POST['booking5'];
    $room_no_5 = $_POST['room_no5'];
    $check_in_5 = $_POST['check_in5'];
    $check_out_5 = $_POST['check_out5'];
    $no_of_rooms_5 = $_POST['no_of_rooms5'];
    $result = mysql_query("UPDATE `hotel`.`rooms_info` SET `room_no` = '$room_no_5',
    `check_in` = '$check_in_5',
    `check_out` = '$check_out_5',
    `no_of_rooms` = '$no_of_rooms_5' WHERE `rooms_info`.`booking_id` = $booking_5;")
    or die(mysql_error());


    $booking_6 = $_POST['booking6'];
    $room_no_6 = $_POST['room_no6'];
    $check_in_6 = isset($_REQUEST["date6"]) ? $_REQUEST["date6"] : "";
    $check_out_6 = isset($_REQUEST["date7"]) ? $_REQUEST["date7"] : "";
    $no_of_rooms_6 = $_POST['no_of_rooms6'];
    if ($room_no_6 != '') {
    $result = mysql_query("INSERT INTO `hotel`.`rooms_info` (`booking_id`, `room_no`, `check_in`, `check_out`, `no_of_rooms`) VALUES ('$booking_6', '$room_no_6', '$check_in_6', '$check_out_6', '$no_of_rooms_6');")
    or die(mysql_error());
    }
    echo "<p style=\"background-color:#E0FFFF;\">Saved Successfully, View changes on Site <a href=\"../\" target=\"_blank\">Click Here</a></p>";
    }

    $result = mysql_query("SELECT *
    FROM `rooms_info`
    ORDER BY `rooms_info`.`booking_id` DESC
    LIMIT 0 , 5")
    or die(mysql_error());

    while ($data = mysql_fetch_array($result)) {
    $booking_id[] = $data['booking_id'];
    $room_no[] = $data['room_no'];
    $check_in[] = $data['check_in'];
    $check_out[] = $data['check_out'];
    $no_of_rooms[] = $data['no_of_rooms'];
    }


    $new_booking_id = $booking_id[0] + 1;
    ?>
    <table border="1">
    <tr><th>Booking Details</th><th></th><th>New Booking</th><th>Booked Rooms</th></tr>
    <tr><td>
    <table>
    <form id="form1" name="form1" method="post" action="">
    <?php
    //get class into the page
    require_once('./classes/tc_calendar.php');

    //instantiate class and set properties
    $myCalendar = new tc_calendar("date6", true);
    $myCalendar->setIcon("./images/iconCalendar.gif");
    $myCalendar->setDate(2, 1, 2013);
    $myCalendar7 = new tc_calendar("date7", true);
    $myCalendar7->setIcon("./images/iconCalendar.gif");
    $myCalendar7->setDate(3, 1, 2013);
    ?>
    <tr><td> <label>Booking ID</label></td><td> <input name="booking1" type="text" size="32" maxlength="40" value="<?php echo $booking_id[0]; ?>" /></td></tr>
    <tr><td><label>Room No</label></td><td> <input name="room_no1" type="text" size="32" maxlength="40" value="<?php echo $room_no[0]; ?>" /></td></tr>
    <tr><td><label>Check In</label> </td><td><input name="check_in1" type="text" size="32" maxlength="40" value="<?php echo $check_in[0]; ?>" /></td></tr>
    <tr><td><label>Check Out</label> </td><td><input name="check_out1" type="text" size="32" maxlength="40" value="<?php echo $check_out[0]; ?>" /></td></tr>
    <tr><td><label>No of Rooms</label> </td><td><input name="no_of_rooms1" type="text" size="32" maxlength="40" value="<?php echo $no_of_rooms[0]; ?>" /></td></tr><br />



    </table>
    <table>


    <tr><td> <label>Booking ID</label></td><td> <input name="booking2" type="text" size="32" maxlength="40" value="<?php echo $booking_id[1]; ?>" /></td></tr>
    <tr><td><label>Room No</label></td><td> <input name="room_no2" type="text" size="32" maxlength="40" value="<?php echo $room_no[1]; ?>" /></td></tr>
    <tr><td><label>Check In</label> </td><td><input name="check_in2" type="text" size="32" maxlength="40" value="<?php echo $check_in[1]; ?>" /></td></tr>
    <tr><td><label>Check Out</label> </td><td><input name="check_out2" type="text" size="32" maxlength="40" value="<?php echo $check_out[1]; ?>" /></td></tr>
    <tr><td><label>No of Rooms</label> </td><td><input name="no_of_rooms2" type="text" size="32" maxlength="40" value="<?php echo $no_of_rooms[1]; ?>" /></td></tr><br />


    </table>
    <table>


    <tr><td> <label>Booking ID</label></td><td> <input name="booking3" type="text" size="32" maxlength="40" value="<?php echo $booking_id[2]; ?>" /></td></tr>
    <tr><td><label>Room No</label></td><td> <input name="room_no3" type="text" size="32" maxlength="40" value="<?php echo $room_no[2]; ?>" /></td></tr>
    <tr><td><label>Check In</label> </td><td><input name="check_in3" type="text" size="32" maxlength="40" value="<?php echo $check_in[2]; ?>" /></td></tr>
    <tr><td><label>Check Out</label> </td><td><input name="check_out3" type="text" size="32" maxlength="40" value="<?php echo $check_out[2]; ?>" /></td></tr>
    <tr><td><label>No of Rooms</label> </td><td><input name="no_of_rooms3" type="text" size="32" maxlength="40" value="<?php echo $no_of_rooms[2]; ?>" /></td></tr><br />


    </table>
    <table>


    <tr><td> <label>Booking ID</label></td><td> <input name="booking4" type="text" size="32" maxlength="40" value="<?php echo $booking_id[3]; ?>" /></td></tr>
    <tr><td><label>Room No</label></td><td> <input name="room_no4" type="text" size="32" maxlength="40" value="<?php echo $room_no[3]; ?>" /></td></tr>
    <tr><td><label>Check In</label> </td><td><input name="check_in4" type="text" size="32" maxlength="40" value="<?php echo $check_in[3]; ?>" /></td></tr>
    <tr><td><label>Check Out</label> </td><td><input name="check_out4" type="text" size="32" maxlength="40" value="<?php echo $check_out[3]; ?>" /></td></tr>
    <tr><td><label>No of Rooms</label> </td><td><input name="no_of_rooms4" type="text" size="32" maxlength="40" value="<?php echo $no_of_rooms[3]; ?>" /></td></tr>



    </table>
    <table>


    <tr><td> <label>Booking ID</label></td><td> <input name="booking5" type="text" size="32" maxlength="40" value="<?php echo $booking_id[4]; ?>" /></td></tr>
    <tr><td><label>Room No</label></td><td> <input name="room_no5" type="text" size="32" maxlength="40" value="<?php echo $room_no[4]; ?>" /></td></tr>
    <tr><td><label>Check In</label> </td><td><input name="check_in5" type="text" size="32" maxlength="40" value="<?php echo $check_in[4]; ?>" /></td></tr>
    <tr><td><label>Check Out</label> </td><td><input name="check_out5" type="text" size="32" maxlength="40" value="<?php echo $check_out[4]; ?>" /></td></tr>
    <tr><td><label>No of Rooms</label> </td><td><input name="no_of_rooms5" type="text" size="32" maxlength="40" value="<?php echo $no_of_rooms[4]; ?>" /></td></tr><br />


    </table>
    </td>
    <td>&nbsp; &nbsp;</td>
    <td>

    <table>


    <tr><td> <label>Booking ID</label></td><td> <input name="booking6" type="text" size="32" maxlength="40" value="<?php echo $new_booking_id; ?>" /></td></tr>
    <tr><td><label>Room No</label></td><td> <input name="room_no6" type="text" size="32" maxlength="40" value="" /></td></tr>
    <tr><td><label>Check In</label> </td><td><?php //output the calendar
    $myCalendar->writeScript();
    ?></td></tr>
    <tr><td><label>Check Out</label> </td><td><?php //output the calendar
    $myCalendar7->writeScript();
    ?></td></tr>
    <tr><td><label>No of Rooms</label> </td><td><input name="no_of_rooms6" type="text" size="32" maxlength="40" value="" /></td></tr><br />
    </table>
    </td>
    <td>
    <?php
    $result = mysql_query("SELECT *
    FROM `rooms_info`
    ORDER BY `rooms_info`.`booking_id` DESC")
    or die(mysql_error());

    global $total_rooms_available;
    $total_rooms_available = 10;
    $booked_room = array();
    $today_date = date("Y-m-d");
    $today_date = strtotime($today_date);
    $tommorow_date = date("Y-m-d", strtotime("+1 day"));
    $tommorow_date = strtotime($tommorow_date);
    while ($row = mysql_fetch_array($result)) {
    $check_in = $row['check_in'];
    $check_out = $row['check_out'];
    $room_no = $row['room_no'];
    $no_of_rooms = $row['no_of_rooms'];
    $check_in = strtotime($check_in);
    $check_out = strtotime($check_out);
    // test for availability with check in and check out date
    if ($check_in <= $today_date && $today_date < $check_out) {

    $room_available = 0;
    $total_rooms_available = $total_rooms_available - $no_of_rooms;
    $booked_room[] = $room_no;
    } // end of if check in loop
    else {
    if ($check_in < $tommorow_date && $tommorow_date <= $check_out) {
    $room_available = 0;
    $total_rooms_available = $total_rooms_available - $no_of_rooms;
    $booked_room[] = $room_no;
    } // end of if checkout loop
    else {
    $room_available = 1;
    } // end of else check out loop
    }
    }
    echo "Available Rooms: $total_rooms_available";
    echo "<br />Booked Room No. <br />";
    foreach ($booked_room as $value) {
    echo "<br />$value<br />";
    }
    ?>
    </td>
    </tr>
    <tr><td><input name="submit" type="submit" value="Save" /> </td></tr>
    </form>
    </table>

    </div>
    </body>
    </html>
  • Logout.php
  • <?php

    // Put this code in first line of web page.
    session_start();
    session_destroy();
    header("location:index.php");
    ?>
In this tutorial we have covered basics of hotel management system.You can extend it as much as you want. I hope it helped you to understand logic behind these type of systems.

السبت، 20 أكتوبر 2012

Maze solving Robot

We have discussed many projects in Robotics before including Line Follower Robot. Maze Solving Robot is similar project but before we discuss about this project, we should know about maze and our objective.

What is Maze?

Maze is a type of puzzle with start start and end points including many dead ends.To solve this puzzle we need to find right path in a fastest possible way.

What type of maze we are going to use for our robot?
Usually, this project requires line maze which is black line on a white background.

Our Objective:

We will build a robot which can find its way in a line maze from start point to end point.

Basic Requirements:

Two Motors: Motors will move robot forward(Both motors running) and help it turns towards left(left motor slow and right fast) or right( right motor slow and left fast).

Five Infrared Sensors: Sensors helps robot to find its path and keeps it updated about the line on the floor.With five sensors their are 32 combination possible but many of them are unlikely to occur in our experiment.For ex. 11111(All indicating black) will never occur because their is only one line and this pattern is showing that line on both side of robot including line on which it is moving.


Concept:

Deciding some rules:
Before implementing this project, you should  decide some basic rules which robot must follow. For example if robot face a situation of T or Four Way , in which direction it should turn? Some students go for right hand rule where robot always give preference to right hand side and some go for left hand rule, though both rules are correct, you need to select one of them and teach robot accordingly.

Intersection:

Define intersections ( turns except only right and only left) where robot needs to take decisions.

Storing Information:

Robot should store information about Dead ends(180 degree turns where pattern is five zeroes 00000) and Bad turns.

Algorithm:

Step 1). Robot will start from first end and move straight as their is only one line.

Step 2). It will move Left because their is only left direction( no intersection so no storage) where it can move.

Step 3). Move Left again(no intersection therefore no storage)

Step 4). Move Left ( Intersection and we apply Left hand Rule) Store L

Step 5). Take U Turn ( Reached Dead End) Store value becomes LU

Step 6). Take Left Again ( Intersection and applies left hand rule) Store value becomes LUL . We move Left but because we took U turn in fifth step we now know that we should not have taken Step 4) .To avoid this mistake for future we will replace LUL to S.

Step 7). Move Straight ( Intersection again but as we are following left hand rule, we will not turn towards right,instead we will follow straight Path) and stored value becomes SS

Step 8). Turn right ( Only right available therefore no intersection)

Step 9.) Reach Target.

So SS will correctly guide robot in next run.

Useful Links:

Maze Solving Robot
Recursion Solving a Maze
Micro mouse: Intelligent autonomous maze solving robot

Related Video:

الاثنين، 15 أكتوبر 2012

Discussion Forum PHP and MYSQL


Download

Today we will learn  how to create a simple discussion forum using PHP and MYSQL. This project is big and can't be covered in single post,so I would divide it into four different posts. Today we will discuss about how we can create skeleton of this project.Next week, we will see how we can use advance features such as jquery,ajax,functions and classes with this project.

File Structure:
We will create five files in root folder and one file db.php (Database configuration file) inside config folder.
index.php : This is home_page or our site from where user can sign in
sign_up.php:  Its for new users registration
discuss.php: Post topics
reply.php : Post replies
log_out.php:log out user


Tools: Apache, PHP and Mysql (Download Xampp or WAMP)

What we are trying to do?

When we think about discussion forum, we know that we will need one login system and only registered can post and reply inside the forum.So, we will create three pages just for user login and they are index.php(login form), sign_up.php(for registering new users) and log_out.php(to remove session).

Other two pages will be used for discussion;first for submitting topic and other one will be used for replying.


Step 1. Create Databases:

I have created database discussion where we will create four tables:
  • categories
  • users
  • topics
  • replies
Database: `discussion`

----------------------------------------------------------

--
-- Table structure for table `categories`
--

CREATE TABLE IF NOT EXISTS `categories` (
`category_id` int(11) NOT NULL auto_increment,
`category_name` varchar(100) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`category_id`)
ENGINE=MyISAM 
DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `replies`
--

CREATE TABLE IF NOT EXISTS `replies` (
  `reply_id` int(11) NOT NULL auto_increment,
 `reply_content` text collate latin1_general_ci NOT NULL,
  `topic_id` int(11) NOT NULL,
  `reply_user_id` int(11) NOT NULL,
  PRIMARY KEY  (`reply_id`)
) ENGINE=MyISAM 
DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `topics`
--

CREATE TABLE IF NOT EXISTS `topics` (
`topic_id` int(11) NOT NULL auto_increment,
`topic_content` text collate latin1_general_ci NOT NULL,
`category_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`topic_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 
COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL auto_increment,
`user_name` varchar(16) collate latin1_general_ci NOT NULL,
`password` varchar(16) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;


Step 2. Inserting some dummy DATA
Fill in the category table with related subjects or anythings related , I have filled it with physics,chemistry,maths,physics and biology:
INSERT INTO `discussion`.`categories` (`category_id`, `category_name`) 
VALUES (NULL, 'physics'), 
(NULL, 'chemistry'), 
(NULL, 'maths'), 
(NULL, 'physics'), 
(NULL, 'biology');
Create Admin user with username and password admin:
INSERT INTO `discussion`.`users` (`user_id`, `user_name`, `password`) VALUES ('1', 'admin', 'admin');
Step 2. Coding Each and very project

index.php
<?php session_start(); 
if(isset($_POST['submit'])) {
include('./config/db.php');
$user_name = $_POST['user_name'];
$password = $_POST['password'];
$user_name = stripslashes($user_name);
$password = stripslashes($password);
$user_name = mysql_real_escape_string($user_name);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM `users` 
WHERE user_name='$user_name' and 
password='$password'";
$result=mysql_query($sql); // execute query

// mysql_num_row is a function used to count number of results we get from the above query
$count=mysql_num_rows($result);

// If result matched $user_name and $password, table row must be 1 row
if($count==1){
$sql="SELECT user_id FROM `users` WHERE user_name='$user_name'";
$result=mysql_query($sql); // execute query
$user_id_array = mysql_fetch_array($result);
$user_id = $user_id_array['user_id'];
// Register $user_name and $user_id and redirect to file "discuss.php"
$_SESSION['user_name'] = $user_name;
$_SESSION['user_id'] = $user_id;
header("location:discuss.php");
}
else {
echo "Please enter correct username and password (check whether capslock is on)";
}

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD 
XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Discussion forum from iprojectideas.blogspot.com</title>
</head>

<body>

<form action="#" method="post" name="topic_form">
<label>Username</label><br /> <input name="user_name" type="text" />
<br />
<label>Password</label><br />
<input name="password" type="text" /><br />
<input name="submit" type="submit" value="submit" />

</form>
<p>New Users <a href="sign_up.php">Sign up now</a></p>

</body>
</html>

sign_up.php
 <?php session_start(); 
if(isset($_POST['submit'])) {
include('./config/db.php');
$user_name = $_POST['user_name'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
$user_name = stripslashes($user_name);
$password = stripslashes($password);
$repassword = stripslashes($repassword);
$user_name = mysql_real_escape_string($user_name);
$password = mysql_real_escape_string($password);
$repassword = mysql_real_escape_string($repassword);
// check for errors
if($user_name == '' || $password == '' || $repassword =='') {
echo "Please fill correct username and password";
}
else if($password != $repassword) {
echo "password does not match , please try again";
}

else {
$sql="SELECT * FROM `users` WHERE user_name='$user_name'";
$result=mysql_query($sql); // execute query

// mysql_num_row is a function used to count number of results we get from the above query
$count=mysql_num_rows($result);

// if user name does not exist than register this user in our database and redirect him to discussion forum
if($count==1){
echo "User name has been already taken, please try again!";
}
else {
$sql = "INSERT INTO `discussion`.`users` (`user_id`, `user_name`, `password`) VALUES (NULL, '$user_name', '$password');";
$result=mysql_query($sql); // execute query
if($result) {

// Register $user_name,$user_id and redirect to file "discuss.php"
// find out user id
$sql="SELECT user_id FROM `users` WHERE user_name='$user_name'";
$result=mysql_query($sql); // execute query
$user_id_array = mysql_fetch_array($result);
$user_id = $user_id_array['user_id'];
$_SESSION['user_name'] = $user_name;
$_SESSION['user_id'] = $user_id;
header("location:discuss.php");
}
else {
echo "Error, please try again";
}
} // end of inner else

} // end of outer else
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sign up | Discussion forum from iprojectideas.blogspot.com</title>
</head>

<body>

<form action="#" method="post" name="topic_form">
<label>Username</label><br /> <input name="user_name" type="text" />
<br />
<label>Password</label><br />
<input name="password" type="text" /><br />
<label>Re-enter Password</label><br /><input name="repassword" type="text" /><br />
<input name="submit" type="submit" value="submit" />

</form>
<p>Already Registered <a href="index.php">Sign in</a></p>

</body>
</html>

discuss.php
<?php 
session_start();
if(!isset($_SESSION['user_name'])) {
header("location:index.php");
}
else {
$user_name = $_SESSION["user_name"];
$user_id = $_SESSION["user_id"];
echo "Welcome $user_name ";
echo "<a href=\"log_out.php\">Log out</a>";
include('./config/db.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Discussion forum from iprojectideas.blogspot.com</title>
</head>

<body>
<?php if(isset($_POST['topic'])) {
$topic = $_POST['topic'];
$category_id = $_POST['category_id'];
$sql = "INSERT INTO `discussion`.`topics` (`topic_id`, `topic_content`, `category_id`, `user_id`) VALUES ('', '$topic', '$category_id', '$user_id');";
$rsd = mysql_query($sql);
echo "Thanks for submitting your topic $topic in $category_id ";

}
else {
?>
<form action="#" method="post" name="topic_form">
<label>Topic</label><br /> <textarea name="topic" cols="100" rows="5"></textarea><br />
<label>Category</label>
<select name="category_id">
<?php $sql = "SELECT * FROM `categories`;";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$category_id = $rs['category_id'];
$category_name = $rs['category_name'];

echo "<option value=\"$category_id\">$category_name</option>";
}
?>
</select><br />
<input name="submit" type="submit" value="submit" />

</form>
<?php }
echo"<h3>Submitted Topics:</h3>";
$sql = "SELECT * FROM `topics` ORDER BY `topics`.`topic_id` DESC;";
$topics = mysql_query($sql);
while ($row = mysql_fetch_array($topics, MYSQL_ASSOC )){
$topic_content = $row['topic_content'];
$topic_id = $row['topic_id'];
echo "<h3>$topic_content</h3>";
$sql = "SELECT * FROM `replies` where `replies`.`topic_id` = $topic_id;";
$replies = mysql_query($sql);
while($row = mysql_fetch_array($replies, MYSQL_ASSOC )) {
$reply_content = $row['reply_content'];
echo "<p> $reply_content</p>";
} // end of while
echo "<br /><a href=\"reply.php?topic_id=$topic_id\">reply</a><br />";
}

?>
</body>
</html>

reply.php
<?php 
session_start();
if(!isset($_SESSION['user_name'])) {
header("location:index.php");
}
else {
$user_name = $_SESSION["user_name"];
$user_id = $_SESSION["user_id"];
echo "Welcome $user_name ";
echo "<a href=\"log_out.php\">Log out</a>";
include('./config/db.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Discussion forum from iprojectideas.blogspot.com</title>
</head>

<body>
<?php if(isset($_POST['reply'])) {
$reply = $_POST['reply'];
$topic_id = $_POST['topic_id'];

$sql = "INSERT INTO `discussion`.`replies` (`reply_id`, `reply_content`, `topic_id`, `reply_user_id`) VALUES (NULL, '$reply', '$topic_id', '$user_id');";
$rsd = mysql_query($sql);
if($rsd) {
echo "Thanks for submitting your reply $reply. <a href=\"discuss.php\">Return Back</a> to view it. "; }
else {
echo "Error, reply submission fail";
}

}
else {
$topic_id = $_GET['topic_id'];
$topic_id= stripslashes($topic_id);
$topic_id = mysql_real_escape_string($topic_id);
echo"<h3>Reply:</h3>";
$sql = "SELECT * FROM `topics` where `topics`.`topic_id` = $topic_id;";
$topics = mysql_query($sql);
$row = mysql_fetch_array($topics, MYSQL_ASSOC );
$topic_content = $row['topic_content'];

echo "<h3>$topic_content</h3>"; ?>
<form action="#" method="post" name="reply_form">
<label>Reply</label><br />
<textarea name="reply" cols="100" rows="5"></textarea><br />
<input type="hidden" name="topic_id" value="<?php echo"$topic_id" ?>" />
<input name="submit" type="submit" value="reply" />
</form>
<?php }
?>
</body>
</html>

log_out.php
<?php 
session_start();
if(!isset($_SESSION['user_name'])) {
header("location:index.php");
}
else {
session_destroy();
header("location:index.php");
}
?>

 config/db.php
<?php 
$db_host='localhost';
$db_database='discussion';
$db_username='YOUR_DB_USERNAME';
$db_password='YOUR_DB_PASSWORD';
$connection = mysql_connect($db_host, $db_username, $db_password);
if (!$connection){ die("Could not connect to the database: <br />". mysql_error( )); }
// Select the database
$db_select = mysql_select_db($db_database); if (!$db_select){
die ("Could not select the database: <br />". mysql_error( )); }


?>

Download

الاثنين، 1 أكتوبر 2012

Study of Cooling Tower

Cooling towers are heat removal devices which are used to transfer heat from cooling water to the atmosphere.

What does a cooling tower do?

1)They promote efficient water uses
2)Prevents environmental damages

Animation shown at the University of Michigan website will help you to understand more about hyperbolic stack-natural draft cooling towers.


How a cooling tower works? 
They work in two ways, first using evaporation of water or by using conventional method of heat ex-changer.Video given below has more explanation about it.

  

Projects:
Increasing Cooling Tower Water Efficiency :By increasing water efficiency of tower, we can save tons of gallons of precious fresh water.

CFD Prediction of Cooling Tower Drift :The CFD (computational fluid dynamics) program predicts plume rise, surface concentrations, plume center-line concentrations and surface drift deposition within the bounds of field experimental accuracy.

Cooling Tower Analysis : Analysis by a team about the performance of four cooling towers and cooling done by them.

Related Presentation:

Thermodynamics of efficient cooling tower

Related Post:

Mechanical Projects

Hydraulic Regenerative Braking System

Regenerative Braking:
How regenerative braking Works ?
More about this braking

Relative PDF :
Regenerative braking system for bicycle
Development of Regenerative braking system using super capacitors for electrical vehicle
Hybrid RBS Presentation
Algorithm for these types of brakes


In hybrid cars, hydraulic regenerative braking system (HRBS) can play significant role to lower the fuel consumption.It recycles energy by converting kinetic energy into potential energy during deceleration using accumulator.A hydraulic accumulator is a pressure storage reservoir in which a non-compressible hydraulic fluid is held under pressure by an external source.And, in this case this external source is high pressure compressed air.

What's the use of storing energy?
This energy can be reused while acceleration which significantly lower the fuel consumption.Moreover, we all use stored energy in some or the other way. When we fill water tank on roof top using electric motors, we are actually storing electric energy in the form of potential energy and this energy can be used later to provide water inside our home.

Why its important?
Energy recycling is the energy recovery process of utilizing energy that would normally be wasted.The regenerative braking system can capture and recycle the normally wasted braking energy during vehicle drive cycle.
Projects:
Useful Links:
How Regenerative braking system works?

Related Video:

Related:
Hydraulics projects