这是jQuery手风琴代码的作用:
$(function() {
$( "#accordion" ).accordion({
header: "h3"
});
});
这是数据库(mysql)的输出,它是循环(不确定循环):
while($showE = mysqli_fetch_array($show))
{
echo $showE['un_name']; /* this should be accordion head */
echo $showE['un_name_dec']; /* this should be accordion description */
}
所以我的问题是,如何在手风琴效果中显示它们,一切正常(我可以从数据库中获取记录),但是手风琴效果未形成((手风琴效果不起作用))以及如何用循环显示它们?
解决方法:
因此,您有两个文件:index.html和load_entries.php
index.html:
<html>
<head>
<!-- Make the imports of your stylesheets and scripts here -->
<script type="text/javascript">
$(function() {
$("#accordion").accordion({header: "h3"});
});
function load_entries() {
$.ajax({
url: "load_entries.php",
complete: function(data) {
$("#accordion").html(data.responseText);
}
});
}
</script>
</head>
<body>
<button onclick="load_entries();">Load</button> <!-- Button to load the entries -->
<div id="accordion">
</div>
</body>
</html>
load_entries.php:
<?php
//connect to your database here
$sql = "SELECT * FROM entries"; //replace entries by your own table name
$result = mysqli_query($sql);
while($row = mysqli_fetch_array($result)) {
echo '<h3>'.$row['un_name'].'</h3>';
echo '<div>'.$row['un_name_dec'].'</div>';
}
?>