Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

html - Is there any ways to target the individual data and put it in PHP session without overwriting it?

I am currently trying to develop a basic car reservation system.I use mysqli_fetch_assoc to retrieve the data from the database and display each data in every row of the table.

The data is displayed successfully.Right now,Im thinking of putting a button for the user to interact with the exact data in the row for every row in the table.For example,a car with a registration number A in row 1 and a car with a registration number B in row 2.

The situation is user can click the button in row 2 and the system will redirect the user to a new page carrying the detail of the car with registration number B.The same situation can be applied to row 1.Is there any way to do this?I tried to use $_SESSION but it was overwritten by the latest data.

Here is my code. The mysqli_fetch_assoc part

@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
body {
  font-family: 'Poppins', sans-serif;
  background-image: url(2109.jpg);
  background-position: center;
  background-size: cover;
}

* {
  margin: 0;
  padding: 0;
  list-style: none;
  text-decoration: none;
}

.sidebar {
  position: fixed;
  left: -300px;
  width: 300px;
  height: 100%;
  background: #042331;
  transition: all .5s ease;
}

.sidebar header {
  font-size: 22px;
  color: white;
  text-align: center;
  line-height: 70px;
  background: #063146;
  user-select: none;
}

.sidebar ul a {
  display: block;
  height: 100%;
  width: 100%;
  line-height: 65px;
  font-size: 20px;
  color: white;
  padding-left: 40px;
  box-sizing: border-box;
  border-top: 1px solid rgba(255, 255, 255, .1);
  border-bottom: 1px solid black;
  transition: .5s;
}

#check {
  display: none;
}

label #btn,
label #cancel {
  position: fixed;
  cursor: pointer;
  background: #042331;
  border-radius: 1px;
}

label #btn {
  left: 40px;
  top: 25px;
  font-size: 35px;
  color: white;
  padding: 6px 12px;
  transition: all .5s;
}

label #cancel {
  z-index: 1111;
  left: -245px;
  top: 17px;
  font-size: 30px;
  color: #0a5275;
  padding: 4px 9px;
  transition: all .5s ease;
}

#check:checked~.sidebar {
  left: 0;
}

#check:checked~label #btn {
  left: 300px;
  opacity: 0;
  pointer-events: none;
}

#check:checked~label #cancel {
  left: 245px;
}

table {
  width: 70%;
  padding: 20px;
  border-spacing: 10px;
  margin-left: auto;
  margin-right: auto;
  background-color: rgba(255, 255, 255, .5);
}

th {
  font-size: 25px;
}

tr {
  font-size: 20px;
}

h1 {
  text-align: center;
  font-size: 4rem;
  color: rgb(255, 255, 255);
  padding: 50px;
}

img {
  width: 150px;
  height: 150px;
}

.title {
  font-weight: bolder;
  font-size: 30px;
}

button {
  background-color: #4CAF50;
  /* Green */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}


/* SideBar CSS
<?php
include("connection.php");
session_start();
if(!isset($_SESSION['userlogged']) || $_SESSION['userlogged'] != 1)
{
    header("Location: index.php");
}
$query = "SELECT * FROM car";
$result = mysqli_query($conn,$query);
?>


  <!DOCTYPE html>
  <html lang="en" dir="ltr">

  <head>
    <meta charset="utf-8">
    <title>Side Menu Bar CSS</title>
    <link rel="stylesheet" href="dashboard.css">
    <link rel="stylesheet" href="carlist.css">
    <link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
    <script src="https://kit.fontawesome.com/a076d05399.js"></script>

  </head>

  <body>
    <input type="checkbox" id="check">
    <label for="check">
        <i class="fas fa-bars" id="btn"></i>
        <i class="fas fa-times" id="cancel"></i>
    </label>
    <div class="sidebar">
      <header>Menu</header>
      <ul>

        <a href="carlist.php"><i class="fas fa-stream"></i><span> Car List </span></a>
        <a href="#"><i class="fas fa-file"></i><span> Reservation Status </span></a>
        <a href="#"><i class="fas fa-power-off"></i><span> Logout </span></a>

      </ul>
    </div>
    <div>
      <div class="carlist">
        <h1>Car List</h1>
        <table>

          <tr>
            <td class="title">Car</td>
            <td class="title">Car Name</td>
          </tr>
          <?php
                    while($rows=mysqli_fetch_assoc($result))
                    {
                ?>
            <tr>
              <td>
                <?php 
                        echo $rows['car_name'];
                        $_SESSION['plate_num'] = $rows['plate_num'];
                        ?>
              </td>
              <td>
                <a href="test.php">HEllo</a>
              </td>
            </tr>
            <?php
                }
                ?>
        </table>
      </div>
    </div>
  </body>

  </html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...