[代码]
<?php
mysql_connect("","","") or die("Could not connect to localhost");
mysql_select_db("") or die( "Could not connect to database");
$names[] = mysql_query("SELECT * FROM list ORDER BY name ASC");
// The list wasn't sorted, if you don't want sorting you can just remove this line.
asort($names);
// Prepare list for accordion.
$accordionData = [];
foreach($names as $name) {
$accordionData[substr($name, 0, 1)][] = $name;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Accordion - Collapse content</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#accordion" ).accordion({
collapsible: true,
active: false
});
});
</script>
</head>
<body>
<div id="accordion">
<?php
// Print accordion, change the echoes to reflect your accordion html.
foreach($accordionData as $index => $names) {
?>
<h3><?php echo strtoupper($index); ?></h3>
<div>
<?php
foreach($names as $name) {
?>
<p><?php echo ucfirst($name); ?></p>
<?php
}
?>
</div>
<?php
}
?>
</div>
我收到两个错误:
警告:substr() 期望参数 1 是字符串,资源在第 14 行的 C:\xampp\htdocs\test.php 中给出
警告:ucfirst() 期望参数 1 是字符串,资源在 C:\xampp\htdocs\test.php 第 49 行给出
如果我将名称从数组中取出,我将如何将名称放入手风琴?