尊龙凯时人生就是搏

ÔõôʹÓÃthinkphp¾ÙÐÐÊý¾ÝÇóºÍ²¢ÅÅÐÐ

°ì·¨1£ºÅþÁ¬Êý¾Ý¿â

»á¼ûThinkPHP¹ÙÍø²¢ÏÂÔØ×îа汾 £¬È»ºó½âѹ²¢½«Æä°²ÅÅÔÚЧÀÍÆ÷ÇéÐÎÖС£ÔÚThinkPHPµÄĿ¼ÖÐ £¬ÐèÒª½¨ÉèÒ»¸öÃûΪTestµÄÏîÄ¿ £¬È»ºóÔÚ¸ÃÏîÄ¿Öн¨ÉèÒ»¸ö¿ØÖÆÆ÷ºÍÄ£×ÓÀ´»ñÈ¡Êý¾Ý¡£

// application/index/controller/Index.php
namespace app\index\controller;

use think\Controller;
use app\index\model\Data;

class Index extends Controller {
    public function index() {
        $list = Data::all();
        // ´ËËæ´¦ÀíÊý¾ÝÇóºÍÅÅÃû
        $this->assign('list', $list);
        return $this->fetch();
    }
}

µÇ¼ºó¸´ÖÆ

// application/index/model/Data.php
namespace app\index\model;

use think\Model;

class Data extends Model {}

µÇ¼ºó¸´ÖÆ

ThinkPHPÌṩÁ˺ܺõÄÊý¾Ý»á¼û²ã £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÉÏÃæµÄ´úÂëÇáËɵؽ«Êý¾Ý´ÓÊý¾Ý¿âÖÐÌáÈ¡³öÀ´¡£

°ì·¨2£ºÇóºÍ

ÎÒÃÇ¿ÉÒÔ½«×ÅʵÏÖΪÈçÏÂËùʾ£º

$sum = 0;
foreach ($list as $item) {
    $sum += $item['field'];
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖÐ £¬ÎÒÃÇÐèÒª½«fieldÌæ»»³ÉÎÒÃÇÒªÇóºÍµÄ×Ö¶ÎÃû¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

°ì·¨3£ºÅÅÐÐ

½ÓÏÂÀ´ £¬ÎÒÃÇÐèÒª¶ÔÊý¾ÝµÄÇóºÍЧ¹û¾ÙÐÐÅÅÐС£ÎÒÃÇÊ×ÏȽ«Êý¾ÝÅÅÐò £¬È»ºóƾ֤ËùÐèµÄ˳ÐòÊä³öÓÐÐò±í¸ñ¡£

function cmp($a, $b) {
    if ($a['sum'] == $b['sum']) {
        return 0;
    }
    return $a['sum'] > $b['sum'] ? -1 : 1;
}
usort($list, "cmp");

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖÐ £¬ÎÒÃÇÐèÒª½«sumÌæ»»³ÉÎÒÃÇËùÐèµÄÇóºÍ×ֶεÄÃû³Æ¡£

°ì·¨4£ºÊä³ö

ÏÖÔÚ £¬ÎÒÃÇÒѾ­Íê³ÉÁËÊý¾ÝµÄÇóºÍºÍÅÅÐÐ £¬ÎÒÃÇÖ»ÐèÒª½«Êý¾Ýƾ֤˳ÐòäÖȾµ½HTMLÖм´¿É¡£

<table>
    <thead>
        <tr>
            <th>Ãû³Æ</th>
            <th>ÇóºÍЧ¹û</th>
            <th>ÅÅÃû</th>
        </tr>
    </thead>
    <tbody>
        {volist name="list" id="vo"}
            <tr>
                <td>{$vo.name}</td>
                <td>{$vo.sum}</td>
                <td>{$i++}</td>
            </tr>
        {/volist}
    </tbody>
</table>

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖÐ £¬ÎÒÃÇÐèÒª½«nameÌ滻ΪÎÒÃÇ´æ´¢Ãû³ÆµÄÁÐ £¬sumÌ滻ΪÎÒÃÇÇóºÍµÄÁС£

ÒÔÉϾÍÊÇÔõôʹÓÃthinkphp¾ÙÐÐÊý¾ÝÇóºÍ²¢ÅÅÐеÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ