簡體   English   中英

如何在現有排序功能中對SQL結果進行排序

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

您好,我在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');

        }

下一段代碼:

<?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