Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在现有排序函数中对SQL结果进行排序_Php_Mysql_Mysqli - Fatal编程技术网

Php 如何在现有排序函数中对SQL结果进行排序

Php 如何在现有排序函数中对SQL结果进行排序,php,mysql,mysqli,Php,Mysql,Mysqli,你好,我有这个排序功能的一个CMS模板。如果条件是第二个条件,我想补充: if(is_array($array)) { foreach($array as $row) { if($row[photos] == 1) { if($isMobile) { include($basepath.'/templates/mobile.content_item_photo.php'); } else {

你好,我有这个排序功能的一个CMS模板。如果条件是第二个条件,我想补充:

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');

        }

我不明白这个问题。“第一个代码函数”是什么意思?你说的“如果条件是第二个…”是什么意思?第一个条件是如果访客来自移动设备,那么我需要它来进行第二次排序,而不是移动设备。包括($basepath.'/templates/template.content_item_photo.php');当我运行脚本时,它开始用这个模板对所有内容进行排序。basepath.'/templates/template.content\u item\u photo.php,因此下一个mysql结果应该与此模板一起列出。包括($basepath.'/templates/template.channel_item_title.php');不,我想我解释的方式不好。好的,原始代码正在检查您是否使用移动设备,如果没有,则开始使用以下模板对库进行排序:templates/template.content\u item\u photo.php。我想要的是,在此页面上添加另一个div层,该层将列出数据库中的信息,即:$result=mysql_query(“SELECT niches.name,niches.record_num from niches ORDER BY name ASC”);但是使用这个模板template.channel\u item\u title.php,结果将列出content\u item\u photo+\u item\u title.php,在非mobileIt的情况下,您似乎必须修改content\u item\u photo.php,然后呢?content\u item\u photo.php所做的只是库的排序算法,但是它们将显示在哪里是由索引页内的代码控制的。所以我想要的是将带有新排序的新div与库的排序放在一起,因为template.channel\u item\u title.php与item\u photo相同,但它只是对标题而不是库进行排序。您将template.content\u item\u 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');

        }