thinkphpÔõÑù·µ»Øij¼¸ÌõÊý¾Ý
Ò»¡¢·µ»Øij¼¸ÌõÊý¾ÝµÄÐèÇ󳡾°
ÔÚWeb¿ª·¢ÖУ¬¾³£»áÓöµ½ÐèÒª·µ»Øij¼¸ÌõÊý¾ÝµÄÐèÇó¡£ÀýÈ磬ÔÚÒ»¸öÍøÕ¾µÄ¡°ÈÈÃÅÎÄÕ¡±Ä£¿éÖУ¬ÐèÒªÖ»·µ»Ø½üÆÚ»á¼ûÁ¿×î¸ßµÄ5ƪÎÄÕ£»»òÕߣ¬ÔÚÒ»¸öµçÉÌÍøÕ¾µÄ¡°ÏúÁ¿ÅÅÐС±Ä£¿éÖУ¬ÐèÒªÖ»·µ»ØÏúÁ¿Ç°Ê®ÃûµÄÉÌÆ·ÐÅÏ¢¡£
¶þ¡¢ThinkPHPÅÌÎÊÓï¾ä¼ò½é
ÔÚѧϰÔõÑù»ñÈ¡Ìض¨Ãü¾Ý֮ǰ£¬ÈÃÎÒÃÇÏÈÏàʶThinkPHPÖеÄÅÌÎÊÓï¾ä¡£Ê¹ÓÃÁ´Ê½²Ù×÷£¨Fluent½Ó¿Ú£©¿ÉÒÔ¹¹½¨SQLÅÌÎÊÓï¾ä£¬ÕâÊÇThinkPHPµÄ×ö·¨¡£ÒÔÏÂÊÇһЩ³£¼ûµÄÅÌÎʲÙ×÷º¯Êý£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
table()£ºÖ¸¶¨ÅÌÎʵıíÃû
field()£ºÉèÖÃÒªÅÌÎʵÄ×Ö¶Î
where()£ºÉèÖÃÅÌÎÊÌõ¼þ
order()£ºÉèÖÃÅÌÎÊЧ¹ûµÄÅÅÐò·½·¨
limit()£ºÉèÖÃÅÌÎÊЧ¹ûµÄÊýÄ¿
select()£ºÖ´ÐÐÅÌÎʲÙ×÷£¬²¢·µ»ØЧ¹û¼¯
Èý¡¢·µ»Ø×îеÄNÌõÊý¾Ý
ÔÚÐí¶àÓ¦Óó¡¾°ÖУ¬ÎÒÃÇÐèÒª·µ»Ø×îеÄNÌõÊý¾Ý¡£Õâ¿ÉÒÔͨ¹ýÒÔÏÂThinkPHP´úÂëʵÏÖ£º
$data = Db::table('my_table')->order('id desc')->limit($N)->select();
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëµÄ¼ÄÒåÊÇ£¬´Ómy_table±íÖÐƾ֤id×ֶνµÐòÅÅÁУ¬È¡³öÇ°NÌõ¼Í¼£¬²¢½«Ð§¹û¼¯ÉúÑÄÔÚ$dataÊý×éÖС£
ËÄ¡¢·µ»Ø»á¼ûÁ¿×î¸ßµÄNÌõÊý¾Ý
ÔÚÍøÕ¾¿ª·¢ÖУ¬Ðí¶àÐèÇóÊÇÐèÒª·µ»Ø»á¼ûÁ¿×î¸ßµÄNÌõÊý¾Ý¡£Õâ¿ÉÒÔͨ¹ýÒÔÏÂThinkPHP´úÂëʵÏÖ£º
$data = Db::table('my_table')->order('views desc')->limit($N)->select();
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëµÄ¼ÄÒåÊÇ£¬´Ómy_table±íÖÐƾ֤views×ֶνµÐòÅÅÁУ¬È¡³öÇ°NÌõ¼Í¼£¬²¢½«Ð§¹û¼¯ÉúÑÄÔÚ$dataÊý×éÖС£
Îå¡¢·µ»Øijһ×ֶεÄTOP NÖµ
ÔÚÐí¶àÇéÐÎÏ£¬ÎÒÃÇÐèÒª»ñȡijһÁеÄÅÅÃûÇ°NµÄÖµ£¬ÀýÈçÏúÊÛ¶îÇ°Ê®µÄÉÌÆ·ÐÅÏ¢¡£Õâ¿ÉÒÔͨ¹ýÒÔÏÂThinkPHP´úÂëʵÏÖ£º
$data = Db::table('my_table')->field('id, name, sales')->order('sales desc')->limit($N)->select();
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëµÄ¼ÄÒåÊÇ£¬´Ómy_table±íÖÐÑ¡Ôñid¡¢name¡¢salesÈý¸ö×ֶΣ¬Æ¾Ö¤sales×ֶνµÐòÅÅÁУ¬È¡³öÇ°NÌõ¼Í¼£¬²¢½«Ð§¹û¼¯ÉúÑÄÔÚ$dataÊý×éÖС£
Áù¡¢·µ»ØÖ¸¶¨¹æÄ£ÄÚµÄÊý¾Ý
ÎÞÒâÎÒÃÇÐèҪŲÓÃij¸öÌض¨¹æÄ£ÄÚµÄÊý¾Ý£¬ÀýÈçÅÌÎÊidÔÚ100ÖÁ200Ö®¼äµÄÓû§ÐÅÏ¢¡£Õâ¿ÉÒÔͨ¹ýÒÔÏÂThinkPHP´úÂëʵÏÖ£º
$data = Db::table('my_table')->where('id', 'between', [100, 200])->select();
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëµÄ¼ÄÒåÊÇ£¬´Ómy_table±íÖÐÑ¡ÔñËùÓÐidÔÚ100µ½200Ö®¼äµÄ¼Í¼£¬²¢½«Ð§¹û¼¯ÉúÑÄÔÚ$dataÊý×éÖС£
ÒÔÉϾÍÊÇthinkphpÔõÑù·µ»Øij¼¸ÌõÊý¾ÝµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡