English 中文(简体)
多个条款,如红色贝兰达
原标题:multiple where clauses in redbeanphp
  • 时间:2012-04-15 14:10:00
  •  标签:
  • php
  • redbean

Im将“善待”项目改为“管理”项目。 I m试图装设一个灯塔,在地块上添加一个灯。 但我不敢肯定如何做到这一点。

Normally i d get a bean like this:

$book = R::load( book , $id);

基本上说的是:

SELECT * FROM book WHERE id =  $id 

但有必要在条款中添加另一项条件:

SELECT * FROM book WHERE id =  $id  AND active = 1

怎样才能与红比海洋实验室合作?

最佳回答

RedBean_Facade::load is using for primary key only.

if you want get beans by a complex query use

<代码>R:find喜欢

$needles = R::find( needle ,  haystack = :haystack 
                                  ORDER BY :sortorder , 
    array(  :sortorder =>$sortorder,  :haystack =>$haystack ));

阅读更多有关R:定义

http://www.redbeanphp.com/manual/Finding_beans

尝试使用 各位都直接用参数撰写问询

R::getAll(  select * from book where 
id= :id AND active = :act , 
array( :id =>$id, :act  => 1) );

更多了解询问

http://www.redbeanphp.com/manual/queries

问题回答

R::find() and R::findOne() is what you are looking for:

$beans=R::find("books","active=? AND id=?",array(1,1));

或者如果你只想一个灯塔:

$bean=R::findOne("books","active=? AND id=?",array(1,1));

<代码>R:find()将返还多个豆类,而R:find One( 只返还单一豆类。

可在技术上使用<代码>R:load(),但必须使用PHP对active进行检查。 a. 如果信标有效,在信标后已装上测试:

$bean=R::load("book",$id);
if($bean->active==1){//valid
   //do stuff
}else{//not valid
   //return error
}

Hope this helps!

这些答案是好的,但可以简化。 你们应当使用的是:

$book = R::find( books , id =:id AND active =:active, array( id  => $id,  active  => 1));

那么,你可以采取标准旁听器,通过交回的数据。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签