【问题标题】:Php - order the current data without reloading the pagephp - 对当前数据进行排序而不重新加载页面
【发布时间】:2017-10-18 08:22:10
【问题描述】:

我是 Web 开发的新手。我想知道是否有任何可能的方法可以在我的页面上订购当前数据(MySQL)而不重新加载页面。

首先我在下表中显示所有数据。

<table class="table">
	 <tr>
	   <th>Title</th>
	   <th>Describe</th>
	   <th>Date <a  href="#"><span name="order" class="glyphicon glyphicon-triangle-bottom"></span></a></th>
	</tr>

<?php
	include 'connect.php';
	global $conn;

	$sql = "SELECT * FROM event";
	$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) 
{
	// output data of each row
	while($row = mysqli_fetch_assoc($result)) 
	{
		echo '<tr>';
		echo '<td>'.$row['title'].'</td>';
		echo '<td>'.$row['description'].'</td>';
		echo '<td>'.$row['data'].'</td>';
		echo '</tr>';
	}
} 
else 
{
	echo "0 results";
}

我想修复,当我点击“Data -on that span with glyphicon”以立即订购数据而不刷新页面时

我试过了,但没有用

if(isset($_GET['order']))
		{
  			$sql = "SELECT * FROM event ORDER BY date ASC";
			$result = mysqli_query($conn, $sql);

 				if (mysqli_num_rows($result) > 0) 
 				{
 				    // output data of each row
 				    while($row = mysqli_fetch_assoc($result)) 
 				    {
 				        echo '<tr>';
 				        echo '<td>'.$row['title'].'</td>';
				    echo '<td>'.$row['description'].'</td>';
					echo '<td>'.$row['data'].'</td>';
					echo '</tr>';
				}
		     } 
		}

【问题讨论】:

  • 您的选择是 JavaScript(通过对后端进行 AJAX 调用以刷新数据或使用数据表等排序库)
  • 你为什么不从头开始订购呢? ORDER BY data 但究竟什么是数据?
  • @clearshot66 我忘了从我的语言翻译 ,, ORDER BY data = ORDER BY date
  • 明白了。那么当你使用 ORDER BY date 时它在做什么呢?您数据库中的日期是什么样的?
  • @clearshot66 In MySQL data - varchar(45),, In html .. 结果如下:2017-05-18

标签: php html mysql web


【解决方案1】:

您需要使用 javascript。 PHP 是一种服务器端语言,它的工作不是做客户端工作。

【讨论】:

    猜你喜欢
    • 2020-04-03
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    相关资源
    最近更新 更多