thinkphp inÅÌÎÊÔõÑù·ÖÒ³
thinkphpÊÇÒ»¸öÆÕ±éʹÓõÄphp¿ò¼Ü£¬ÆäÌṩÁËÇ¿Ê¢µÄÅÌÎʹ¦Ð§£¬¿ÉÒÔʹÓû§Àû±ãµØÖ´ÐÐÖÖÖÖÖØ´óµÄÅÌÎʲÙ×÷¡£ÆäÖУ¬inÅÌÎÊÓï¾äÊdz£ÓõÄÅÌÎÊÓï¾äÖ®Ò»¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃthinkphpÖеÄinÅÌÎÊÓï¾äʵÏÖ·ÖÒ³¹¦Ð§¡£
Ò»¡¢Ê²Ã´ÊÇinÅÌÎÊ
ÔÚÏàʶinÅÌÎÊÔõÑù·Öҳ֮ǰ£¬ÎÒÃÇÐèÒªÏÈÏàʶʲôÊÇinÅÌÎÊ¡£ÔÚÊý¾Ý¿âÅÌÎÊÖУ¬inÅÌÎÊÓï¾äÊÇÒ»ÖÖÓÃÓÚÔÚ¸ø¶¨Ò»×éÖµµÄÇéÐÎÏ£¬Æ¥ÅäÅÌÎÊÌõ¼þµÄÓï¾ä¡£ÀýÈ磬ÎÒÃÇÏëÒª²éÕÒÒ»¸öÉÌÆ·£¬ËüµÄÖÖ±ðΪµçÊÓ»òµçÄÔ»òÊÖ»ú£¬ÄÇô¾Í¿ÉÒÔʹÓÃinÅÌÎÊÓï¾ä¡£inÅÌÎÊÓï·¨ÈçÏ£º
SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...);
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬INºóÃæ¸úµÄÊÇÒ»¸öÀ¨ºÅ£¬À¨ºÅÄÚÊÇÖµÁÐ±í¡£ÀýÈ磺
SELECT * FROM products WHERE category_name IN ('ÊÖ»ú', 'µçÄÔ', 'µçÊÓ');
µÇ¼ºó¸´ÖÆ
ÕâÌõSQLÓï¾ä½«»á·µ»ØÖÖ±ðΪÊÖ»ú¡¢µçÄÔ»òµçÊÓµÄÉÌÆ·ÐÅÏ¢¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
¶þ¡¢ÔõÑùʹÓÃinÅÌÎÊʵÏÖ·ÖÒ³
ÏàʶÁËinÅÌÎÊÓï¾äµÄ»ù±¾Ó÷¨ºó£¬ÎÒÃÇ¿ÉÒÔ×îÏȽâ¾öÔõÑùʹÓÃinÅÌÎÊÓï¾äʵÏÖ·ÖÒ³¡£·ÖÒ³ÊÇÖ¸ÔÚÅÌÎʵÄЧ¹û¼¯Öн«Ð§¹û·ÖΪÈô¸ÉÒ³£¬ÒÔ±ãÓû§¿ÉÒÔÖðÒ³ä¯ÀÀÅÌÎÊЧ¹û¡£ThinkPHPÌṩÁËÇ¿Ê¢µÄ·ÖÒ³¹¦Ð§£¬¿ÉÒÔÀû±ãµØʵÏÖ·ÖÒ³¹¦Ð§¡£
ÔÚThinkPHPÖУ¬·ÖÒ³ÀàλÓÚ\think\paginatorÃüÃû¿Õ¼äÖС£Ê¹Ó÷ÖÒ³¹¦Ð§ÐèÒª¾ÙÐÐÒÔÏÂÈý¸ö°ì·¨£º
1.ÅÌÎÊÊý¾Ý
ʹÓÃinÅÌÎÊÓï¾äÅÌÎʳöÐèÒª¾ÙÐзÖÒ³µÄÊý¾Ý£¬ÀýÈ磺
$goods = Db::name('goods') ->where('category_id','in',[1,2,3,4,5]) ->order('price DESC') ->paginate(10);
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄ´úÂ뽫»áÅÌÎʳöÉÌÆ·ÖÖ±ðΪ1¡¢2¡¢3¡¢4¡¢5µÄÉÌÆ·£¬²¢Æ¾Ö¤¼ÛÇ®´Ó¸ßµ½µÍÅÅÐò£¬²¢ÇÒÿҳÏÔʾ10ÌõÊý¾Ý¡£
2.»ñÈ¡·ÖÒ³Êý¾Ý
ͨ¹ýŲÓÃpaginate()ÒªÁ죬ÎÒÃÇ¿ÉÒÔ»ñÈ¡µ½·ÖÒ³Æ÷¹¤¾ß¡£·ÖÒ³Æ÷¹¤¾ß°üÀ¨Ä¿½ñÒ³Â롢ÿҳÏÔʾµÄÊý¾ÝÊýÄ¿ºÍ×ܹ²µÄÊý¾ÝÌõÊýµÈÐÅÏ¢¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ·½·¨»ñÈ¡·ÖÒ³Æ÷ÖеÄÊý¾Ý£º
$goods = $goods->items();
µÇ¼ºó¸´ÖÆ
3.äÖȾ·ÖÒ³ÊÓͼ
·ÖÒ³Æ÷¹¤¾ß»¹°üÀ¨ÁË·ÖÒ³ÐÅÏ¢µÄäÖȾҪÁ죬ÎÒÃÇ¿ÉÒÔʹÓÃÕâЩҪÁìÉúÒòËØÒ³ÊÓͼ¡£ÀýÈ磺
<div> <?php echo $goods->render(); ?></div>
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇͨ¹ýrender()ÒªÁìÌìÉúÁË·ÖÒ³Æ÷µÄhtmlÊÓͼ£¬È»ºó½«Æä²åÈëµ½ÁËÒ³ÃæÖС£ÕâÑù£¬ÎÒÃǾÍÍê³ÉÁËʹÓÃinÅÌÎÊÓï¾äʵÏÖ·ÖÒ³µÄ¹¦Ð§¡£
Èý¡¢×ܽá
±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃThinkPHPÖеÄinÅÌÎÊÓï¾äʵÏÖ·ÖÒ³¡£inÅÌÎÊÓï¾ä¿ÉÒÔÀû±ãµØ¶Ô¸ø¶¨µÄ¶à¸öÖµ¾ÙÐÐÅÌÎÊ£¬¶ø·ÖÒ³Æ÷Ôò¿ÉÒÔÀû±ãµØ½«Êý¾Ý·ÖÒ³ÏÔʾ¡£ÍŽáʹÓÃÕâÁ½¸ö¹¦Ð§£¬ÎÒÃÇ¿ÉÒÔÀû±ãµØʵÏÖÖØ´óµÄÅÌÎʺͷÖÒ³¹¦Ð§¡£
ÒÔÉϾÍÊÇthinkphp inÅÌÎÊÔõÑù·ÖÒ³µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡