简体   繁体   English

如何在现有排序功能中对SQL结果进行排序

[英]how to sort SQL result in an existing sorting function

Hello I have this sorting function ine one template of CMS. 您好,我在CMS的一个模板中具有此排序功能。 I would like to add if the condition is the second one: 我想补充一下条件是否为第二个条件:

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

        }

I want to add the following MySQL result to show also 我想添加以下MySQL结果以同样显示

$result = mysql_query("SELECT niches.name, niches.record_num FROM niches ORDER BY name ASC");

which is used in this template for sorting: 在此模板中用于排序:

include($basepath.'/templates/template.channel_item_title.php');  

Any ideas how this can be integrated inside the first code function? 有什么想法可以将其集成到第一个代码功能中吗?

So here is the code of the main index template: 所以这是主要索引模板的代码:

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

I don't think I get your question, but we have to start somewhere... 我想我没有收到您的问题,但是我们必须从某个地方开始...

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

        }

Next block of code: 下一段代码:

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

        }

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

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