×ðÁú¿­Ê±¹ÙÍøµÇ¼

thinkphp5ÔõÑùʵÏÖÅÌÎʼÆÊý¹¦Ð§

Ò»¡¢ÅÌÎÊ

ÔÚThinkPHP5ÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýDbÀà»òÕßModelÀà¶ÔÊý¾Ý¿â¾ÙÐÐÅÌÎÊ ¡£ÕâÀïÒÔModelÀàΪÀý¾ÙÐÐÏÈÈÝ ¡£

»ù±¾ÅÌÎÊ

ÎÒÃÇ¿ÉÒÔͨ¹ýselect()ÒªÁìʵÏÖ»ù±¾µÄÅÌÎʲÙ×÷ £¬ÈçÏ£º

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

//½¨ÉèÄ£×Ó¹¤¾ß
$user = new UserModel();
//ÅÌÎÊuser±íÖÐÐÕÃûΪÕÅÈýµÄ¼Í¼
$result = $user -> where('name','ÕÅÈý') -> select();

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÖÐ £¬where()ÒªÁìÓÃÓÚÖ¸¶¨ÅÌÎÊÌõ¼þ £¬Æä²ÎÊýÃûÌÃΪwhere(ÅÌÎÊ×Ö¶Î,ÅÌÎÊÖµ) ¡£µ±ÅÌÎÊÌõ¼þΪ¶à¸ö×Ö¶Îʱ £¬ÎÒÃÇ¿ÉÒÔʹÓÃÁ´Ê½²Ù×÷ ¡£

ÈçÏ£º

$user -> where('name','ÕÅÈý') -> where('age',20) -> select();

µÇ¼ºó¸´ÖÆ

´Ë´¦ÌåÏÖÅÌÎÊuser±íÖÐÐÕÃûΪÕÅÈý £¬ÄêËêΪ20µÄ¼Í¼ ¡£

Ìõ¼þÅÌÎÊ

ÎÒÃÇ¿ÉÒÔÔÚÅÌÎÊÓï¾äÖмÓÈëwhere()¡¢whereOr()¡¢whereLike()µÈÌõ¼þÅÌÎÊÒªÁì £¬ÒÔʵÏÖ¸üÎÞаµÄÅÌÎʲÙ×÷ ¡£

ÈçÏ£º

//ÅÌÎÊuser±íÖÐÄêËê´óÓÚ20£¬ÇÒÐÔ±ðΪÄеļͼ
$result = $user -> where('age','>',20) -> where('gender','ÄÐ') -> select();
//ÅÌÎÊuser±íÖÐÄêËêСÓÚ20»òÐÔ±ðΪŮµÄ¼Í¼
$result = $user -> where('age','<',20) -> whereOr('gender','Å®') -> select();
//ÅÌÎÊuser±íÖÐÐÕÃû°üÀ¨¡®ÕÅ¡¯µÄ¼Í¼
$result = $user -> whereLike('name','%ÕÅ%') -> select();

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏ´úÂëÖÐ £¬where()ÒªÁìºÍwhereOr()ÒªÁì»®·ÖÌåÏÖÅÌÎÊÌõ¼þΪ¡°ÇÒ¡±ºÍ¡°»ò¡±µÄ¹Øϵ £¬Æä²ÎÊýÃûÌÃÏàͬ£»¶øwhereLike()ÒªÁìÓÃÓÚʵÏÖÄ£ºýÅÌÎÊ £¬ÆäµÚ¶þ¸ö²ÎÊýÌåÏÖÅÌÎÊÆ¥ÅäµÄÌõ¼þ ¡£

±ðµÄ £¬ÎÒÃÇ»¹¿ÉÒÔÁ´Ê½Å²ÓÃorder()À´ÅÅÐòÅÌÎÊЧ¹û £¬ÈçÏ£º

$result = $user -> where('age','>',20) -> order('age desc') -> select();

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÌåÏÖÅÌÎÊuser±íÖÐÄêËê´óÓÚ20µÄ¼Í¼ £¬²¢Æ¾Ö¤ÄêËê´Ó´óµ½Ð¡¾ÙÐÐÅÅÐò ¡£

·ÖÒ³ÅÌÎÊ

µ±ÎÒÃÇÐèÒªÅÌÎÊ´ó×ÚÊý¾Ýʱ £¬¿ÉÒÔʹÓ÷ÖÒ³ÅÌÎʹ¦Ð§ÒÔ±ÜÃâÊý¾ÝÁ¿¹ý´óµ¼ÖÂЧÀÍÆ÷¸ºÔعýÖØ ¡£

ÔÚThinkPHP5ÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃlimit()ÒªÁìʵÏÖ·ÖÒ³ÅÌÎÊ ¡£limit()ÒªÁìÓÐÁ½¸ö²ÎÊý £¬µÚÒ»¸ö²ÎÊýÌåÏÖÆðʼƫÒÆÁ¿ £¬µÚ¶þ¸ö²ÎÊýÌåÏÖÿҳÏÔʾµÄ¼Í¼Êý ¡£

ÈçÏ£º

// ÿҳÏÔʾ3Ìõ¼Í¼£¬ÅÌÎʵÚ2Ò³µÄÊý¾Ý
$result = $user -> limit(3,3) -> select();

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂëÌåÏÖÅÌÎÊuser±íÖеÚ2Ò³ £¬Ã¿Ò³ÏÔʾ3Ìõ¼Í¼ ¡£

¶þ¡¢¼ÆÊý

ÔÚThinkPHP5ÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýcount()ÒªÁìʵÏÖ»ù±¾µÄ¼ÆÊý¹¦Ð§ ¡£

ÈçÏ£º

//ÅÌËãuser±íÖмͼ×ÜÊý
$count = $user -> count();
//ÅÌËãuser±íÖÐÄêËê´óÓÚ20µÄ¼Í¼Êý
$count = $user -> where('age','>',20) -> count();

µÇ¼ºó¸´ÖÆ

ÐèҪעÖصÄÊÇ £¬count()ÒªÁìÏÖʵÉÏÊǶÔÊý¾Ý¿â¾ÙÐÐÁËÒ»´ÎÅÌÎÊ £¬Òò´ËÔÚÏÖʵӦÓÃÖÐ £¬Ó¦¸ÃÖ»¹ÜïÔÌ­²»ÐëÒªµÄ¼ÆÊý²Ù×÷ £¬ÒÔÌá¸ßÓ¦ÓÃÐÔÄÜ ¡£

ÒÔÉϾÍÊÇthinkphp5ÔõÑùʵÏÖÅÌÎʼÆÊý¹¦Ð§µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

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

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

QR code
ÍøÕ¾µØͼ