คำสั่ง sql select ให้ข้อมูลเรียงตามวันที่ ปัจจุบันลงไปเพื่อจะได้ง่ายต่อการจัดการข่าว ง่ายครับ
คำสั่ง sql select ให้ข้อมูลเรียงตามวันที่ ปัจจุบันลงไปเพื่อจะได้ง่ายต่อการจัดการข่าวครับเพราะแก้โค้ดเขาอีกทีครับ
<?php require_once('Connections/webb.php'); ?>
<?php
// Load the common classes
require_once('includes/common/KT_common.php');
// Require the MXI classes
require_once ('includes/mxi/MXI.php');
// Load the required classes
require_once('includes/tfi/TFI.php');
require_once('includes/tso/TSO.php');
require_once('includes/nav/NAV.php');
// Make unified connection variable
$conn_webb = new KT_connection($webb, $database_webb);
// Filter
$tfi_listnews1 = new TFI_TableFilter($conn_webb, "tfi_listnews1");
$tfi_listnews1->addColumn("news.n_name", "STRING_TYPE", "n_name", "%");
$tfi_listnews1->addColumn("news.n_desc", "STRING_TYPE", "n_desc", "%");
$tfi_listnews1->addColumn("news.n_date", "DATE_TYPE", "n_date", "=");
$tfi_listnews1->addColumn("news.n_status", "STRING_TYPE", "n_status", "%");
$tfi_listnews1->addColumn("group_news.g_di", "NUMERIC_TYPE", "g_id", "=");
$tfi_listnews1->Execute();
// Sorter
$tso_listnews1 = new TSO_TableSorter("rsnews1", "tso_listnews1");
$tso_listnews1->addColumn("news.n_name");
$tso_listnews1->addColumn("news.n_desc");
$tso_listnews1->addColumn("news.n_date");
$tso_listnews1->addColumn("news.n_status");
$tso_listnews1->addColumn("group_news.g_name");
$tso_listnews1->setDefault("news.n_name DESC");
$tso_listnews1->Execute();
// Navigation
$nav_listnews1 = new NAV_Regular("nav_listnews1", "rsnews1", "", $_SERVER['PHP_SELF'], 30);
mysql_select_db($database_webb, $webb);
$query_tities = "SELECT office_name FROM office_name";
$tities = mysql_query($query_tities, $webb) or die(mysql_error());
$row_tities = mysql_fetch_assoc($tities);
$totalRows_tities = mysql_num_rows($tities);
mysql_select_db($database_webb, $webb);
$query_Recordset1 = "SELECT g_name, g_di FROM group_news ORDER BY g_name";
$Recordset1 = mysql_query($query_Recordset1, $webb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
//NeXTenesio3 Special List Recordset
$maxRows_rsnews1 = $_SESSION['max_rows_nav_listnews1'];
$pageNum_rsnews1 = 0;
if (isset($_GET['pageNum_rsnews1'])) {
$pageNum_rsnews1 = $_GET['pageNum_rsnews1'];
}
$startRow_rsnews1 = $pageNum_rsnews1 * $maxRows_rsnews1;
$NXTFilter_rsnews1 = "1=1";
if (isset($_SESSION['filter_tfi_listnews1'])) {
$NXTFilter_rsnews1 = $_SESSION['filter_tfi_listnews1'];
}
$NXTSort_rsnews1 = "news.n_name DESC";
if (isset($_SESSION['sorter_tso_listnews1'])) {
$NXTSort_rsnews1 = $_SESSION['sorter_tso_listnews1'];
}
mysql_select_db($database_webb, $webb);
$query_rsnews1 = sprintf("SELECT news.n_name, news.n_desc, news.n_date, news.n_status, group_news.g_name AS g_id, news.n_id FROM news LEFT JOIN group_news ON news.g_id = group_news.g_di WHERE %s ORDER BY %s", $NXTFilter_rsnews1, $NXTSort_rsnews1);
$query_limit_rsnews1 = sprintf("%s LIMIT %d, %d", $query_rsnews1, $startRow_rsnews1, $maxRows_rsnews1);
$rsnews1 = mysql_query($query_limit_rsnews1, $webb) or die(mysql_error());
$row_rsnews1 = mysql_fetch_assoc($rsnews1);
if (isset($_GET['totalRows_rsnews1'])) {
$totalRows_rsnews1 = $_GET['totalRows_rsnews1'];
} else {
$all_rsnews1 = mysql_query($query_rsnews1);
$totalRows_rsnews1 = mysql_num_rows($all_rsnews1);
}
$totalPages_rsnews1 = ceil($totalRows_rsnews1/$maxRows_rsnews1)-1;
//End NeXTenesio3 Special List Recordset
$nav_listnews1->checkBoundries();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css.css">
<title>:: <?php echo $row_tities['office_name']; ?> ::</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
<script src="includes/nxt/scripts/list.js" type="text/javascript"></script>
<script src="includes/nxt/scripts/list.js.php" type="text/javascript"></script>
<script type="text/javascript">
$NXT_LIST_SETTINGS = {
duplicate_buttons: true,
duplicate_navigation: true,
row_effects: true,
show_as_buttons: true,
record_counter: true
}
</script>
<style type="text/css">
/* NeXTensio3 List row settings */
.KT_col_n_name {width:150px; overflow:hidden;}
.KT_col_n_desc {width:120px; overflow:hidden;}
.KT_col_n_date {width:120px; overflow:hidden;}
.KT_col_n_status {width:80px; overflow:hidden;}
.KT_col_g_id {width:140px; overflow:hidden;}
</style>
</head>
<body>
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" valign="top"><?php
mxi_includes_start("header.php");
require(basename("header.php"));
mxi_includes_end();
?></td>
</tr>
<tr>
<td width="17%" valign="top"><?php
mxi_includes_start("menu.php");
require(basename("menu.php"));
mxi_includes_end();
?></td>
<td width="71%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4%" valign="top"> </td>
<td width="96%" valign="top">
<div class="KT_tng" id="listnews1">
<h1> จัดการระบบข่าวสาร
<?php
$nav_listnews1->Prepare();
require("includes/nav/NAV_Text_Statistics.inc.php");
?>
</h1>
<div class="KT_tnglist">
<form action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" method="post" id="form1">
<div class="KT_options"> <a href="<?php echo $nav_listnews1->getShowAllLink(); ?>"><?php echo NXT_getResource("Show"); ?>
<?php
// Show IF Conditional region1
if (@$_GET['show_all_nav_listnews1'] == 1) {
?>
<?php echo $_SESSION['default_max_rows_nav_listnews1']; ?>
<?php
// else Conditional region1
} else { ?>
<?php echo NXT_getResource("all"); ?>
<?php }
// endif Conditional region1
?>
<?php echo NXT_getResource("records"); ?></a>
</div>
<table cellpadding="2" cellspacing="0" class="KT_tngtable">
<thead>
<tr class="KT_row_order">
<th> <input type="checkbox" name="KT_selAll" id="KT_selAll"/>
</th>
<th id="n_name" class="KT_sorter KT_col_n_name <?php echo $tso_listnews1->getSortIcon('news.n_name'); ?>"> <a href="<?php echo $tso_listnews1->getSortLink('news.n_name'); ?>">หัวข้อข่าว</a> </th>
<th id="n_desc" class="KT_sorter KT_col_n_desc <?php echo $tso_listnews1->getSortIcon('news.n_desc'); ?>"> <a href="<?php echo $tso_listnews1->getSortLink('news.n_desc'); ?>">รายละเอียด</a> </th>
<th id="n_date" class="KT_sorter KT_col_n_date <?php echo $tso_listnews1->getSortIcon('news.n_date'); ?>"> <a href="<?php echo $tso_listnews1->getSortLink('news.n_date'); ?>">วันที่ลงข่าว</a> </th>
<th id="n_status" class="KT_sorter KT_col_n_status <?php echo $tso_listnews1->getSortIcon('news.n_status'); ?>"> <a href="<?php echo $tso_listnews1->getSortLink('news.n_status'); ?>">สถานะ</a> </th>
<th id="g_id" class="KT_sorter KT_col_g_id <?php echo $tso_listnews1->getSortIcon('group_news.g_name'); ?>"> <a href="<?php echo $tso_listnews1->getSortLink('group_news.g_name'); ?>">หมวดข่าว</a> </th>
<th> </th>
</tr>
</thead>
<tbody>
<?php if ($totalRows_rsnews1 == 0) { // Show if recordset empty ?>
<tr>
<td colspan="7"><?php echo NXT_getResource("The table is empty or the filter you've selected is too restrictive."); ?></td>
</tr>
<?php } // Show if recordset empty ?>
<?php if ($totalRows_rsnews1 > 0) { // Show if recordset not empty ?>
<?php do { ?>
<tr class="<?php echo @$cnt1++%2==0 ? "" : "KT_even"; ?>">
<td><input type="checkbox" name="kt_pk_news" class="id_checkbox" value="<?php echo $row_rsnews1['n_id']; ?>" />
<input type="hidden" name="n_id" class="id_field" value="<?php echo $row_rsnews1['n_id']; ?>" />
</td>
<td><div class="KT_col_n_name"><?php echo KT_FormatForList($row_rsnews1['n_name'], 30); ?></div></td>
<td><div class="KT_col_n_desc"><?php echo KT_FormatForList($row_rsnews1['n_desc'], 20); ?></div></td>
<td><div class="KT_col_n_date"><?php echo KT_formatDate($row_rsnews1['n_date']); ?></div></td>
<td><div class="KT_col_n_status"><?php echo KT_FormatForList($row_rsnews1['n_status'], 20); ?></div></td>
<td><div class="KT_col_g_id"><?php echo KT_FormatForList($row_rsnews1['g_id'], 20); ?></div></td>
<td><a class="KT_edit_link" href="edit_news.php?n_id=<?php echo $row_rsnews1['n_id']; ?>&KT_back=1"><?php echo NXT_getResource("edit_one"); ?></a> <a class="KT_delete_link" href="#delete"><?php echo NXT_getResource("delete_one"); ?></a> </td>
</tr>
<?php } while ($row_rsnews1 = mysql_fetch_assoc($rsnews1)); ?>
<?php } // Show if recordset not empty ?>
</tbody>
</table>
<div class="KT_bottomnav">
<div>
<?php
$nav_listnews1->Prepare();
require("includes/nav/NAV_Text_Navigation.inc.php");
?>
</div>
</div>
<div class="KT_bottombuttons">
<a href="list_groupnews.php">สร้างกลุ่มข่าวสาร</a>
<div class="KT_operations"> <a class="KT_edit_op_link" href="#" onclick="nxt_list_edit_link_form(this); return false;"><?php echo NXT_getResource("edit_all"); ?></a> <a class="KT_delete_op_link" href="#" onclick="nxt_list_delete_link_form(this); return false;"><?php echo NXT_getResource("delete_all"); ?></a> </div>
<span> </span>
<select name="no_new" id="no_new">
<option value="1">1</option>
<option value="3">3</option>
<option value="6">6</option>
</select>
<a class="KT_additem_op_link" href="edit_news.php?KT_back=1" onclick="return nxt_list_additem(this)"><?php echo NXT_getResource("add new"); ?></a> </div>
</form>
</div>
<br class="clearfixplain" />
</div>
<p> </p></td>
</tr>
</table></td>
<td width="12%" valign="top"><?php
mxi_includes_start("picmenu.php");
require(basename("picmenu.php"));
mxi_includes_end();
?></td>
</tr>
<tr>
<td colspan="3" valign="top"><?php
mxi_includes_start("footer.php");
require(basename("footer.php"));
mxi_includes_end();
?></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($tities);
mysql_free_result($Recordset1);
mysql_free_result($rsnews1);
?>Tag : PHP, Ms SQL Server 2008
Date :
2013-11-06 11:42:18
By :
thelak
View :
2136
Reply :
3
เติม order by n_date desc ในบรรทัดที่ 69 ครับ
Date :
2013-11-06 11:48:36
By :
Dragons_first
ไม่ได้เลยครับ error แบบนี้ครับ อิอิ
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by news.n_date desc, news.n_status, group_news.g_name AS g_id, news.n_id F' at line 1
Date :
2013-11-06 13:54:50
By :
thelak
Code (PHP)
ORDER BY ชื่อตาราง.ชื่อฟิลวันที่ DESC
ใส่ไว้ท้ายสุดของประโยค SQL ที่ทำการคิวรี่ข้องมูล หลัง Where หลัง Group by หลังทุกๆอย่าง"
Date :
2013-11-06 14:27:58
By :
meannerss
Load balance : Server 01