PHP Classes

MySQL data display in a table and clickable events

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  MySQL data display in a table and...  
Subject:MySQL data display in a table and...
Summary:Get the value of current table value drawn from Mysql Database
Author:Teacha Kyng
Date:2013-09-17 03:23:15
Update:2013-09-17 04:27:44

  1. MySQL data display in a table and...   Reply   Report abuse  
Teacha Kyng - 2013-09-17 04:27:44
I have a code that displays data from Mysql database. I want that when a user clicks on one of the fields drawn from the database, the database should display corresponding results of that ID.
As you can see in the code below, the code loops through data in the database and select std_id and std_name and display them in an HTML table within a form. I want that, when a user clicks on the button it should display other data in another page such as age, adress, phone... What code would I need to write? Your support will be greatly appreciated.


//database variables

//these variables are from a form used to display the current data
$level = $_POST['level_group'];
$room = $_POST['room_group'];

mysqli_set_charset($con, "utf8");
// Check connection
if (mysqli_connect_errno())
echo "Failed to connect to MySQL: " . mysqli_connect_error();
$result = mysqli_query($con,"SELECT std_id, std_name FROM students WHERE std_level LIKE '$level%' AND std_room LIKE '$room';");

<table border='1' id='mytable'>
<tr bgcolor = #99CCFF>
<th><b>Student ID</b></th>

//loop through the database

while($row = mysqli_fetch_array($result))
echo"<form action='view_one_student.php' method='post'>";
echo "<tr bgcolor = '#c0eae4n' id = 'listings'>";
echo "<td name= 'stdid'>" . $row['std_id'] . "</td>";
echo "<td>" . $row['std_name'] . "</td>";
echo "<td>" . '<input type="submit" value="view"> <input type="submit" value="sdq">' . "</td>";
echo "</tr>";
echo "</form>";
echo "</table>";