Hybreeder Hybreeder - 3 months ago 12
MySQL Question

How to display Multiple Ids records in time order on same page using PHP?

I have 1000+ records in Original table and have to display each record on same page depending upon user id.

For Example:- I entered user id 1, Record will display on same screen but if i entered user id 2 or any user id than both record should be display on same screen.
I am able to retrieve single records on same page.

Please help me in this.

Html

<form action="" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<input type="text" name="userid">
<input type="submit" name="submit" value="Login">
</form>


Php

//retriving records
$query="SELECT * from dailyentry WHERE id=$id";
$result = $conn->query($query);

<table border="1">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>JoinindDate</th>
<th>Term</th>
</tr>
</thead>
<tbody>
<?php

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>{$row['ID']} </td>
<td>{$row['Name']}</td>
<td>{$row['JoinindDate']}</td>
<td>{$row['Term']}</td>
</tr>
";

}
}
else {
echo "Invalid user id";
}
?>
</tbody>


</table>


I am getting individual records on screen.I need output link this.

enter image description here

Answer

Thanks for your support,

Finally i found my solution, What i did,First record will check in Temp_tbl,If record found than will display "Id already exists" if not found than fetch record form Original table and inserted on Temp_tbl depending on user input Id.

After that in last query that will check current date and display on same page.

Whatever id will insert in text field value will display below of last user id on same page. below is code which i tried and work for me.

//TO check record is available or not in temp table
$query = "SELECT * FROM Temp_tbl WHERE id=$id AND DATE(LoginTime)=CURDATE()";
$result = $conn->query($query);

if (mysqli_num_rows($result) > 0) {
  echo "User id is  already exists";
}
else {
  //copy records from original table and inserting in Temp table
$sql = "INSERT into Temp_tbl (Name,Joining_date,Term,ID,LoginTime)
SELECT Name,Joining_date,Term,ID,now() FROM original_tbl
WHERE id=$id";

 $result1 = $conn->query($sql);
}


//retrive all records with current date and display on same page
$query="SELECT * FROM Temp_tbl WHERE DATE(LoginTime)=CURDATE()";
$result = $conn->query($query);

HTML

<form action="" enctype="multipart/form-data" method="post" accept-charset="utf-8">
        <input type="text" name="userid">
        <input type="submit" name="submit" value="Login">
    </form>
    <table border="1">
  <thead>
    <tr>
      <th>SrNo</th>
      <th>Name</th>
      <th>Joining date</th>
       <th>Term</th>
      <th>Userid</th>
       <th>Login Time</th>
    </tr>
  </thead>
  <tbody>
    <?php

    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "
        <tr>
        <td>{$row['SrNo']} </td>
        <td>{$row['Name']}</td>
        <td>{$row['Joining_date']}</td>
        <td>{$row['Term']}</td>
        <td>{$row['ID']}</td>
         <td>{$row['LoginTime']}</td>
    </tr>
        ";

      }
  }

    ?>
  </tbody>


</table>
Comments