<style type="text/css">
div {
display: none;
}
</style>
function display_detail(id){
var sid='s'+id;
if( document.getElementById(id).style.display == 'inline' ){
If the details layer is not displayed then we will display the layer by managing style.display property. We will also change the symbol to - giving option to user to close the opened details.
document.getElementById(id).style.display = 'inline';// show details
If details are displayed then we will hide the div layer by managing the style display property. function display_detail(id){
var sid='s'+id;
if( document.getElementById(id).style.display == 'inline' ){
document.getElementById(id).style.display = 'none'; // Hide the details div
document.getElementById(sid).innerHTML = '+'; // Change the symbol to +
}else {
document.getElementById(id).style.backgroundColor = '#ffff00'; // Add different color to background
document.getElementById(id).style.display = 'inline'; // show the details
document.getElementById(sid).innerHTML = '-'; //Change the symbol to -
} // end of if else
} // end of function
require "config.php"; // MySQL connection string
You can get full details of MySQL PDO connection string here.
$count="SELECT name,id,class,mark,sex FROM student LIMIT 10";
Now we will execute the query and display the records. Note each record has two div layers and as per the style property all layers are hidden. So we have given special inline style property to display our symbols.
echo "<table>";
foreach ($dbo->query($count) as $row) {
$sid='s' . $row[id];
echo "<tr ><td><div id='$sid' style="display:inline" onclick=display_detail($row[id])> + </div> $row[name]</td></tr>";
echo "<tr ><td><div id=$row[id]><b>Class</b> : $row[class] <b> Mark </b>: $row[mark] <b>SEX</b> : $row[sex]</div></td></tr>";
}
echo "</table>";
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.
| koushik pramanik | 22-11-2014 |
| great thanks to solve different type of problems. i am grateful of this site | |