如何在现有的排序功能中对SQL结果进行排序
您好,我有这种排序功能在CMS的一个模板中。我想补充,如果条件是第二个:如何在现有的排序功能中对SQL结果进行排序
if(is_array($array)) {
foreach($array as $row) {
if($row[photos] == 1) {
if($isMobile) {
include($basepath.'/templates/mobile.content_item_photo.php');
}
else
{
include($basepath.'/templates/template.content_item_photo.php');
}
我想补充以下的MySQL结果也显示
$result = mysql_query("SELECT niches.name, niches.record_num FROM niches ORDER BY name ASC");
这是在这个模板中使用排序
:
include($basepath.'/templates/template.channel_item_title.php');
任何想法如何可以集成到第一个代码函数中?
因此,这里的主要指标模板的代码:
<?
session_start();
if(($_REQUEST[mode] == 'favorites' || $_REQUEST[mode] == 'my_uploads') && !$_SESSION[username]) {
header("Location: /login.php");
}
include('admin/db.php');
include($basepath.'/includes/inc.seo.php');
$cacheName = $_SERVER[REQUEST_URI];
$cacheResult = getCache($cacheName);
$cacheTotalPages = getCache("total_pages$cacheName");
if($cacheResult && $cacheTotalPages) {
$array = $cacheResult;
$total_pages = $cacheTotalPages;
}
else {
include($basepath.'/includes/inc.index_queries.php');
while($row = mysql_fetch_assoc($result)) {
$array[] = $row;
}
if($thispage != 'favorites' && $_GET[mode] != 'my_uploads') {
setCache($cacheName,$array,$overall_cache_time);
setCache("total_pages$cacheName",$total_pages,$overall_cache_time);
}
}
$thisfile = 'index';
$webpage="index";
if($isMobile) {
include($basepath.'/templates/mobile.overall_header.php');
}
else {
include($basepath.'/templates/template.overall_header.php');
}
if(empty($_GET[mode]) && !$_GET[page]) {
include($basepath.'/templates/template.home.php');
}
if($webpage=="index" && empty($_GET[mode]) && !$_GET[page])
{}
else
{
if(is_array($array)) {
foreach($array as $row) {
if($row[photos] == 1) {
if($isMobile) {
include($basepath.'/templates/mobile.content_item_photo.php');
}
else
{
include($basepath.'/templates/template.content_item_photo.php');
}
}
else {
if($isMobile) {
include($basepath.'/templates/mobile.content_item.php');
}
else
{
include($basepath.'/templates/template.content_item.php');
}
}
}
}
else {
echo "Sorry, no results were found.";
}
}
if($isMobile) {
include($basepath.'/templates/mobile.overall_footer.php');
}
else {
include($basepath.'/templates/template.overall_footer.php');
}
?>
我不认为我得到了你的问题,但我们必须从某个地方开始......
<?php
if(is_array($array)) {
foreach($array as $row) {
if($row[photos] == 1) {
if($isMobile) {
include($basepath.'/templates/mobile.content_item_photo.php');
}
else
{
include($basepath.'/templates/template.content_item_photo.php');
}
下一页块的代码:
<?php
$result = mysql_query("SELECT niches.name, niches.record_num FROM niches ORDER BY name ASC");
if(is_array(result)) {
foreach($result as $row) {
if($row[photos] == 1) {
if($isMobile) {
include($basepath.'/templates/mobile.content_item_photo.php');
}
else
{
include($basepath.'/templates/template.channel_item_title.php');
}
当我运行脚本时,它原来是开始用这个模板排序everyhing。 basepath。'/ templates/template.content_item_photo.php,所以下一个mysql结果应该用这个模板列出。包括:($基本路径 '/模板/ template.channel_item_title.php'); – user981220 2013-03-26 23:11:43
也许这样?检查编辑... – bestprogrammerintheworld 2013-03-26 23:20:51
不,我想我解释它的方式不好。好的原始代码正在检查您是否使用移动设备,如果不是,则使用此模板开始对图库进行排序:templates/template.content_item_photo.php。我想要的是,在此页面上添加另一个div层,该层将列出来自数据库的信息,它是这一个:$ result = mysql_query(“SELECT niches.name,niches.record_num FROM niches ORDER BY name ASC”); 但使用此模板template.channel_item_title.php,所以结果将列出content_item_photo + _item_title.php,在不移动的情况下 – user981220 2013-03-26 23:42:26
我不明白这个问题。 “第一代码功能”是什么意思? “如果条件是第二个......”是什么意思? – bestprogrammerintheworld 2013-03-26 22:49:16
第一个条件是如果访问者来自移动设备,那么我需要它进行第二次排序,而不是针对移动设备。包括:($基本路径 '/模板/ template.content_item_photo.php'); – user981220 2013-03-26 22:58:40