<html> <head> <link rel="stylesheet" href="css/booklist.css"> <title>Search data by its ID</title> <script type="text/javascript"> function out(){ alert("Checkout Items Successful!"); } </script> </head> <div class ="background"> <h1>Library Checkout System</h1> <h2>Loan/Request Your Books Here</h2> <form action="" method="POST"> <input type="text" name="id" placeholder="Please enter Book ID" /> <input type="submit" name="search" value="Search By ID" /> </form> <table border="2" id="newton"> <tr> <th>Product Name</th> <th>Quantity</th> <th>Returned Date</th> </tr><br><br> <?php $connection = mysqli_connect("localhost","root", ""); $db = mysqli_select_db($connection,"myfirstdb"); session_start(); if (!isset($_SESSION['id'])) { $_SESSION['id'] = array(); } if(isset($_POST['search'])) { $id = $_POST['id']; array_push($_SESSION['id'],$id); //Here we have declared a session array. We can add elements to it by array_push function.// $_SESSION['id'] = array_unique($_SESSION['id']); //array_unique: Removes duplicate values from an array $id = implode(',',$_SESSION['id']); //implode : returns a strings from the elements of an array.// // instead of changing the database of each row, the implode() function adds the rows according to the selected id entered.// // this function is the key for solving my original problem.// $query = "SELECT * FROM `table3` where id in ($id)"; $query_run = mysqli_query($connection, $query); while($row = mysqli_fetch_array($query_run)) { ?> <tr> <td> <?php echo $row ['product_name']; ?> </td> <td> <?php echo $row ['quantity']; ?> </td> <td> <?php echo $row ['returned_date']; ?> </td> </tr> <?php } } ?> </table> <br> <input type="submit" name="send" value="Confirm Booklist" onclick="out()" /> </form> </div> </body> <a href=""></a><a href=""></a> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)