Commit 24646f29 authored by G.K.V.S.S.R.PAVAN's avatar G.K.V.S.S.R.PAVAN

added final php code

parent 8c863d51
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "projectbus1";
$conn = mysqli_connect("localhost","root","","projectbus1");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ((isset($_POST['submit'])))
{
echo ".......................................................................................................CITYBUS<--->KL_RTC...................................................................................................... ";
echo "<br>";
$presentlocation = $_POST['presentlocation'];
$destination = $_POST['destination'];
echo "present location-$presentlocation";
echo "<br>";
echo "destination-$destination";
echo "<br>";
$sqlwselect = "SELECT * FROM `destination` WHERE `destination`.`destination` <= $presentlocation ";
$resultselect= mysqli_query($conn,$sqlwselect);
while($roww = mysqli_fetch_array($resultselect))
{
$seatselect= $roww['seatnum'];
echo " seattt.....$seatselect";
$sqlselect = "INSERT INTO assignseat(Seatnum) VALUES('$seatselect')";
$resultinsert=mysqli_query($conn,$sqlselect);
}
$sqlw = "DELETE FROM `destination` WHERE `destination`.`destination` <= $presentlocation ";
$resu=mysqli_query($conn,$sqlw);
$sqlwdeleting = "DELETE FROM `deleting` WHERE `deleting`.`destination` <= $presentlocation ";
$resu=mysqli_query($conn,$sqlwdeleting);
$count="SELECT * FROM destination";
$resulttt=mysqli_query($conn,$count);
$num_row=mysqli_num_rows($resulttt);
//for deletetable....
$countdelete="SELECT * FROM deleting";
$resultdeleting=mysqli_query($conn,$countdelete);
$num_row_delete=mysqli_num_rows($resultdeleting);
$num_rows=$num_row+$num_row_delete;
echo "Total no of passengers-$num_rows \n";
echo "<br>";
if($num_rows<"40")
{echo "seats are available";
echo "<br>";}
else
{echo "seats are not available";
echo "<br>";}
$sqlww = "SELECT MAX(seatnum) as max_seatnum FROM destination";
$resultt=mysqli_query($conn,$sqlww);
if (!$resultt) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$row=mysqli_fetch_array($resultt);
//$seatno=$row['S.No'];
//$destination=$row['destination'];
//printf("%d\n",$row[0]"."<br>";
//echo "pav";
$seat=$row['max_seatnum'];
$seat=$seat+1;
if($num_rows<"40")
{
$countt="SELECT * FROM assignseat";
$resultttt=mysqli_query($conn,$countt);
//echo "value2-$resulttt";
$num_roww=mysqli_num_rows($resultttt);
$num_rowsinassign=$num_roww;
echo "noofemptyseats=$num_rowsinassign";
if($num_rowsinassign > "0")
{
$sqlassign="SELECT MIN(Seatnum) as min_seatnum FROM assignseat";
$resultassign=mysqli_query($conn,$sqlassign);
if (!$resultassign) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$rowassign=mysqli_fetch_array($resultassign);
$seat=$rowassign['min_seatnum'];
echo "Seatnum-$seat";
$sqlassigndelete="DELETE FROM `assignseat` WHERE Seatnum IN (select min(Seatnum) from `assignseat`)";
$resultassigndelete=mysqli_query($conn,$sqlassigndelete);
}
else
{
echo "seatnum-$seat";
}
// echo "need to add more code";
/**for($abc=1;$abc<=40;$abc++)
{
$sqlquery="SELECT * FROM destination where 'destination'.'seatnum'=$abc";
$sqlresult=mysqli_query($conn,$sqlquery);
// $roww=mysqli_fetch_array($sqlresult);
//$seatfor=$roww['seatnum'];
echo "forloop-$sqlresult";
echo "<br>";
if(!$sqlresult)
{
echo "seatnuminside-$abc";
$seat=$abc;
printf("Error: %s\n", mysqli_error($conn));
//exit();
break;
}*/
// }
echo "<br>";
}
else if($num_rows>"40")
{
//$sqlelseif="SELECT * FROM destination WHERE destination < '$destination' ";
$sqlelseif="SELECT * FROM destination WHERE destination < '$destination' ";
$resultif=mysqli_query($conn,$sqlelseif);
if (!$resultif)
{
echo "no lesser destination available";
printf("Error: %s\n", mysqli_error($conn));
exit();
}
while($row = mysqli_fetch_array($resultif))
{
// echo "helloo";
$presentatdestination = $row['present'];
$destinationatdestination = $row['destination'];
$seatatdestination = $row['seatnum'];
}
// echo "presentvaluees-$presentatdestination";
//echo "destinationvalues-$destinationatdestination";
//echo "seatvaluees-$seatatdestination";
$sql = "INSERT INTO deleting (present,destination,seatnum) VALUES('$presentatdestination','$destinationatdestination','$seatatdestination')";
$result=mysqli_query($conn,$sql);
if (!$result)
{
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$sqlwgreater = "DELETE FROM `destination` WHERE `destination`.`seatnum` = $seatatdestination ";
$resu=mysqli_query($conn,$sqlwgreater);
echo "seat-$seatatdestination";
echo "<br>";
$seat=$seatatdestination;
}
/* echo "testing-$resultif";
if (!$resultif) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$rowif=mysqli_fetch_array($resultif);
$seat=$rowif['seatnum'];
$comingplace=$rowif['destination'];
echo "seatnumelseif-$seat"."at-$comingplace";
echo "<br>";
}
else
{
echo "seatnum=$seat";
echo "<br>";
}*/
$sql = "INSERT INTO destination (present,destination,seatnum) VALUES('$presentlocation','$destination','$seat')";
$result=mysqli_query($conn,$sql);
if (!$result) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$sql = "INSERT INTO temp (present,destination,seatnum) VALUES('$presentlocation','$destination','$seat')";
$result=mysqli_query($conn,$sql);
if (!$result)
{
printf("Error: %s\n", mysqli_error($conn));
exit();
}
echo "...............................................................................................THANKS FOR USING KL_RTC...................................................................................................... ";
//echo "value2-$result"."<br>";
//$x++;
// $Seatnum=110178;
//$sql = "INSERT INTO seatnumt (Seatnum) VALUES('$Seatnum')";
//$result=mysqli_query($conn,$sql);
//echo "hlooo";
}
/*if ($conn->query($sql) === TRUE) {
header('Location: retrive.php');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}*/
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment