This is my first post on some Q&A site. Point out my tiniest mistakes and correct me. I've started learning PHP and I am using WAMP server. I am having multiple rendering issues. I will present one first. I have an index.php page on which I want to display five tables namely Branch, Student, Subject, Exam and Marks. Now I have kept display buttons for each tables mentioned above on the same page. I don't want the page to get refreshed so the input type for the button is "button" not "submit". And then I want to check if the button is clicked or not so I am using isset($_POST['button']) where button is the name of display button for respective table. And if the button is clicked then I am displaying the datatable for that particular table only while other tables are hidden.
Рендеринг одной таблицы за раз: я хочу, чтобы при нажатии кнопки «Показать ветку таблицы» отобразилась таблица Branch, а после этого, если я нажму кнопку Display Student Table, тогда должна отображаться таблица Student, а остальные таблицы должны быть отображены скрыты, а также для всех таблиц. Теперь приведенный ниже код имеет jquery, который слишком избыточен, и я хочу его оптимизировать. Кроме того, у меня есть часть моего кода PHP, в котором отображается таблица ветвей, тег div тега - branch1, а для ученика - ученик1 и аналогично. При нажатии на кнопку ветви дисплея я ничего не вижу. Это означает, что if (isset ($ _ POST ['display_branch'])) не работает при нажатии кнопки. Также есть тег div для каждой таблицы и имеет другой идентификатор, но тот же класс (например, рендер)
Я хотел бы знать, где я здесь не прав, и я не хочу, чтобы страница была перезагружена снова.
JQuery:
$('.render').hide();
$('#display_branch').click(function (event) {
$('#student1').hide();
$('#subject1').hide();
$('#exam1').hide();
$('#marks1').hide();
$('#branch1').show();
});
$('#display_student').click(function (event) {
$('#subject1').hide();
$('#exam1').hide();
$('#marks1').hide();
$('#branch1').hide();
$('#student1').show();
});
$('#display_subject').click(function (event) {
$('#subject1').show();
$('#exam1').hide();
$('#marks1').hide();
$('#branch1').hide();
$('#student1').hide();
});
$('#display_exam').click(function (event) {
$('#subject1').hide();
$('#exam1').show();
$('#marks1').hide();
$('#branch1').hide();
$('#student1').hide();
});
$('#display_marks').click(function (event) {
$('#subject1').hide();
$('#exam1').hide();
$('#marks1').show();
$('#branch1').hide();
$('#student1').hide();
});
Кнопки дисплея:
<div id="display" style="position:absolute; top:100px;">
<form action="" method="post">
<input type="button" id="display_branch" name="display_branch" value="Display Branch Table" >
<input type="button" id="display_student" name="display_student" value="Display Student Table">
<input type="button" id="display_subject" name="display_subject" value="Display Subject Table">
<input type="button" id="display_exam" name="display_exam" value="Display Exam Table">
<input type="button" id="display_marks" name="display_marks" value="Display Marks Table">
</form>
</div>
Фрагмент кода PHP:
if(isset($_POST['display_branch']))
{
$result = mysql_query("SELECT * FROM branch");?>
<div class="render" id="branch1" style="position:absolute; left:200px; top:150px;">
<table id="datatables" class="display">
<thead>
<tr>
<th>Branch ID</th>
<th>Branch Name</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_array($result)) {
$branch_id= $row['branch_id'];
$branch_name = $row['branch_name'];?>
<tr>
<td><?php echo $branch_id;?></td>
<td><?php echo $branch_name;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>}
Я много искал и много раз пробовал, но не понял. Надеюсь, что это обсуждение поможет некоторым другим решить подобные проблемы.