Commit 42ea2b5b authored by G.K.V.S.S.R.PAVAN's avatar G.K.V.S.S.R.PAVAN

modified php code

parent 24646f29
<?php
echo "<body style='background-color:white'>";
$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"<br>";echo"<br>";echo"<br>";echo"<br>";echo"<br>";echo"<br>";
echo "<p align=center>WELCOME TO KL_RTC</p>";
//echo "<br>";
$presentlocation = $_POST['presentlocation'];
$destination = $_POST['destination'];
if($presentlocation==1)
{echo "<p align=center>Present location-VIJAYAWADA </p>";}
elseif($presentlocation==2)
{echo "<p align=center>Present location-TADEPALLI </p>";}
elseif($presentlocation==3)
{echo "<p align=center>Present location-PATHURRU</p>";}
elseif($presentlocation==4)
{echo "<p align=center>Present location-MANGALAGIRI</p>";}
elseif($presentlocation==5)
{echo "<p align=center>Present location-GUNTUR</p>";}
//echo " To ";
if($destination==1)
{echo "<p align=center>Destination-VIJAYAWADA</p>";}
elseif($destination==2)
{echo "<p align=center>Destination-TADEPALLI</p>";}
elseif($destination==3)
{echo "<p align=center>Destination-PATHURRU</p>";}
elseif($destination==4)
{echo "<p align=center>Destination-MANGALAGIRI</p>";}
elseif($destination==5)
{echo "<p align=center>Destination-GUNTUR</p>";}
//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+1;
echo "<p align=center>Total no of passengers-$num_rows</p>";
//echo "Total no of passengers-$num_rows \n";
//echo "<br>";
if($num_rows<"40")
{
echo "<p align=center>seats are available</p>";
//{echo "seats are available";
//echo "<br>";
}
else
{
echo "<p align=center>seats are not available</p>";
//{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 "<p align=center>Seatnum-$seat</p>";
$sqlassigndelete="DELETE FROM `assignseat` WHERE Seatnum IN (select min(Seatnum) from `assignseat`)";
$resultassigndelete=mysqli_query($conn,$sqlassigndelete);
}
else
{
echo "<p align=center>seatnum-$seat</p>";
}
// 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);
while($rowgreater=mysqli_fetch_array($resultif))
{
$greaterdestination=$rowgreater['destination'];
$greater="INSERT INTO greater('destination') values ('$greaterdestination')";
$sqlgreatercon=mysqli_query($conn,$greater);
}
$greaterrows=mysqli_num_rows($resultif);
//echo "....$greaterrows.....";
if (!$resultif)
{
echo "no lesser destination available";
printf("Error: %s\n", mysqli_error($conn));
exit();
}
if($greaterrows== 0)
{
$seat=0;
// echo "no lesser destination available";
}
else
{
$resultif=mysqli_query($conn,$sqlelseif);
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 "<p align=center>seat-$seatatdestination at destination-$destinationatdestination</p>";
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 "<p align=center>THANKS FOR USING KL_RTC</p>";
//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