简体   繁体   English

是否可以更改sql排序顺序而无需重新加载页面?

[英]Possible to change sql sort order without reloading page?

Code for example: 代码例如:

    <?php
        $sql = "SELECT * FROM `table_name` ORDER BY `first_name` DESC";
        $result = mysql_query($sql) or die(mysql_error());
        if (mysql_num_rows($result) < 1) {
            echo "Database is empty";
        } else {
            while ($details = mysql_fetch_array($result)) {
    ?>

Here would be various calls for $details amongst HTML, like: 以下是HTML中$ details的各种调用,例如:

<a href="<?php echo $details[8]; ?>">Link</a>

And close it with: 并使用以下命令关闭它:

    <?php
            }
        }
    ?>  

What I'd like to do is be able to change the sql sort order without reloading/changing the page. 我想做的是能够更改sql排序顺序,而无需重新加载/更改页面。 Any ideas? 有任何想法吗?

Once you have returned the result set to your application, you can re-sort it there. 将结果集返回给您的应用程序后,您可以在其中重新排序。 No need to issue a new query to change the sort-order, though I suppose you could. 尽管我想可以,但无需发出新查询来更改排序顺序。

If you're a novice, you can try an off-the-shelf product like this: 如果您是新手,可以尝试这样的现成产品:

http://phpgrid.com/ http://phpgrid.com/

Once the page is rendered the PHP is finished, resulting in a page of 100% HTML. 呈现页面后,PHP完成,从而形成100%HTML页面。 If you want to refresh without reloading then you would have to have a PHP file that takes an argument and conducts this SELECT. 如果要刷新而不重新加载,则必须具有一个带参数并执行此SELECT的PHP文件。 Then, based on which link the user clicks, you would use JavaScript to conduct an Ajax request. 然后,根据用户单击的链接,您将使用JavaScript进行Ajax请求。 And then refresh the contents of the page based on the Ajax return. 然后根据Ajax返回刷新页面内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM