使动态表可排序 [英] Making dynamic table sortable
问题描述
我正在做一个小项目,我在
数据库中创建一个表。这是代码,Dreamweaver,大部分,
写的:
***
<?php
mysql_select_db($ database_tdream,$ tdream);
$ query_rstdream =" SELECT * FROM albums ORDER BY` year` ASC" ;;
$ rstdream = mysql_query($ query_rstdream,$ tdream)或死亡
(mysql_error());
$ row_rstdream = mysql_fetch_assoc($ rstdream);
$ totalRows_rstdream = mysql_num_rows($ rstdream);
?>
***
< table cellspacing =" 0">
< thead>
< tr>
< td> ;专辑< / td>
< td>年< / td>
< td> Era< / td>
< td>类型< / td>
< / tr>
< / thead>
< tbody>
<?php do {?>
<?php
$ class =($ class ==''odd'')? ''偶''''''奇怪'';
?>
< tr class ="<?php echo $ class?>" >
< td><?php echo $ row_rstdream [''Name'']; ?>< / td>
< td><?php echo $ row_rstdream [''Year'']; ?>< / td>
< td><?php echo $ row_rstdream [''Era'']; ?>< / td>
< td><?php echo $ row_rstdream [''Type'']; ?>< / td>
< / tr>
<?php} while($ row_rstdream = mysql_fetch_assoc($ rstdream));
?>
< / tbody>
< / table>
***
很抱歉这些例子的长度。我对代码的作用有一个基本的理解,所以如果我知道我正朝着正确的方向前进,我应该能够修改它。我的
对象是通过单击
标题列使该表可排序。我的数据库表中有一个额外的列
是一个auto_increment计数器。有人会有一些想法或
代码,可以帮我解决这个问题吗?我不确定如何接受它,并且希望对
问题有一个简单的答案。
TIA
Ian
-
http://www.bookstacks.org/
I''m doing a small project right now where I create a table from a
database. This is the code, which Dreamweaver, for the most part,
has written:
***
<?php
mysql_select_db($database_tdream, $tdream);
$query_rstdream = "SELECT * FROM albums ORDER BY `year` ASC";
$rstdream = mysql_query($query_rstdream, $tdream) or die
(mysql_error());
$row_rstdream = mysql_fetch_assoc($rstdream);
$totalRows_rstdream = mysql_num_rows($rstdream);
?>
***
<table cellspacing="0">
<thead>
<tr>
<td>Album</td>
<td>Year</td>
<td>Era</td>
<td>Type</td>
</tr>
</thead>
<tbody>
<?php do { ?>
<?php
$class = ($class == ''odd'') ? ''even'' : ''odd'';
?>
<tr class="<?php echo $class ?>">
<td><?php echo $row_rstdream[''Name'']; ?></td>
<td><?php echo $row_rstdream[''Year'']; ?></td>
<td><?php echo $row_rstdream[''Era'']; ?></td>
<td><?php echo $row_rstdream[''Type'']; ?></td>
</tr>
<?php } while ($row_rstdream = mysql_fetch_assoc($rstdream));
?>
</tbody>
</table>
***
Sorry for the length of the examples. I have a basic
understanding of what the code is doing, so I should be able to
modify it if I knew I was heading in the right direction. My
object is to make this table sortable, by clicking on the column
headers. I have an additional column in my database table which
is an auto_increment counter. Would anyone have some ideas or
code that could help me figure this out? I''m not sure how to
approach it, and was hoping that there was a simple answer to the
problem.
TIA
Ian
--
http://www.bookstacks.org/
推荐答案
database_tdream,
database_tdream,
tdream);
tdream);
query_rstdream =" SELECT * FROM albums ORDER BY` year`ASC";
query_rstdream = "SELECT * FROM albums ORDER BY `year` ASC";
这篇关于使动态表可排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!