a) この質問が既に回答されている場合、事前にお詫び申し上げます。検索しましたが、見つけた回答を使用できません。b) 私はあまり熟練したプログラマーではなく、学習しようとしています...
これをできるだけ短くするには...
- 私は検索可能でソート可能なデータベースを備えた完全に機能するサイトを持っています (かなり前に同僚が私のために構築したものなので、なぜ私はさらに混乱しているのでしょうか)
- データベースから入力するドロップダウン フィルターを追加したい
- コードは JavaScript と PHP を参照しています。私が理解していることから、PHP は私のためにテーブル データを入力し、javascript は「xx エントリを表示」フィルタと検索ボックスをトリガーします - どちらも素晴らしいです
私の問題は、作業に追加したいドロップダウンのコードを取得できないことです。ドロップダウンを取得してデータを入力できますが、実際にデータをフィルター処理することはできません:(
<?php
$dbhost = 'localhost';
$dbuser = 'database';
$dbpass = 'password;
$dbname = 'marchmadness';
$table = 'leaderboard';
//connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Leaderboard</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" type="image/png" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="assets/css/main.css">
<link rel="stylesheet" type="text/css" href="assets/css/listing.css" media="all" />
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" language="javascript" src="assets/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
/* This triggers the cool filtering stuff, without this it's just a normal table of data */
$('table').dataTable({
"iDisplayLength": 10
});
});
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</script>
</head>
<body id="listing">
<div id="wrapper">
<div id="topbox" align="center">
<img src="_Images/maddnessheader.png" width="539" height="296" align="center" /></div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<?
$sql="SELECT Title FROM leaderboard";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["leaderboard"];
$thing=$row["Title"];
$options.="<OPTION VALUE=\"$id\">".$thing.'</option>';
}
?>
<SELECT NAME=thing>
<OPTION VALUE=0>Choose
<?=$options?>
</SELEC
T>
<table align="center">
<thead>
<tr>
<th>Title</th>
<th>Name</th>
<th>Call Coding (%)</th>
<th>FizzBack SAT Score (%)</th>
</tr>
</thead>
<tbody>
<?php
//get the information from the database
$result = mysql_query("SELECT * FROM `$table`;") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo '<tr>';
// print out the data from the database. Notice how the text inside $row[] matches up with the headers in phpmyadmin
echo '<td>' . htmlentities($row['Title']) . '</td>';
echo '<td>' . htmlentities($row['Name']) . '</td>';
echo '<td>' . htmlentities($row['CC']) . '</td>';
echo '<td>' . htmlentities($row['FZB']) . '</td>';
echo "</tr>\n";
}
?>
</tbody>
</table>
</div>
</body>
</html>
必要なものを追加するには、javascript を操作する必要があると思います。これは、機能するドロップダウンと検索ボックスがそこから来ているためです...しかし、javascript を吸う :-\ 誰かが助けてくれたら、本当に感謝します。必要に応じて、既存の Java も共有できます:D
乾杯!