English 中文(简体)
Red bean php 联系
原标题:red bean php find by relation
  • 时间:2011-10-03 18:49:47
  •  标签:
  • php
  • redbean

这似乎只是一个简单的问题,但我有些how。

如果我与下列人士一起创建:

list($product1, $product2, $product3) = R::dispense( product , 3);
...

和以下几类:

list($cat1, $cat2) = R::dispense( category , 2);
...

之后,它们与以下方面的联系:

$product1->sharedCategory[] = $cat1;
$product3->sharedCategory[] = $cat1;

然后,我如何询问所有与目录1美元相关的产品? 我应回馈产品1和3。

同我一样,简单明了。 在我的原体中,这是一位没有人才的,因此总是能够把红灯送给一种q,但必须有一种办法,来做到这一点。

感谢。

最佳回答

我认为,这是围绕着(如果我不正确的话)的另一种方式,因为从逻辑上讲,一类产品不像你所定义的那样是多种产品。

======== 部分==================

I deleted a small source posted here because the manual Manuall is super easy and much better and very helpful with sample code on how to connect, make association, updates etc etc. I am sure you will benefit a lot from it. If there is any difficulty with the manual glad to help.

================================================================================================================================================================================================================================================================ 补充资料 ================================================================================================================================================================================================================================================================

在此,我只谈一些来源代码,没有改变我的磨损。 本着这一守则的精神,它以你想要的方式开展工作!

<?PHP
echo  <pre> ;

require( rb.php ); 
$toolbox = R::setup( mysql:host=localhost;dbname=my_ORM , root ,  );
$farm = R::dispense( building );

//create the product list
list($product1,$product2,$product3) = R::dispense( product ,3);
//add attributes 
$product1->name= prod1 ;
$product2->name= prod2 ;
$product3->name= prod3 ;


//create a list of categories 
list($category1,$category2) = R::dispense( category ,2);
//add attributes 
$category1->name= categ1 ;
$category2->name= categ2 ;

//the connect beans together
R::associate($category1,$product1);
R::associate($category1,$product2);
R::associate($category1,$product3);
R::associate($category2,$product3);

//then store
R::store($product1);
R::store($product2);
R::store($product3);
R::store($category1);
R::store($category2); 

//get id for category 1
$categId=R::getCell( " select  `id` from `category` where `name`= categ1   ");
//get products for category 1
$results = 
R::getAll( "
SELECT  `product`.`id`,`product`.`name` 
FROM `product`  left JOIN `category_product`
on `category_product`.`product_id`= `product`.`id` 
where  `category_id`= ".$categId."  ");
//display
print_r($results);

//get categories for product3
$prodId=R::getCell( " select  `id` from `product` where `name`= prod3   ");
$results = 
R::getAll( "
SELECT  `category`.`id`,`category`.`name` 
FROM `category`  left JOIN `category_product`
on `category_product`.`category_id`= `category`.`id` 
where  `product_id`= ".$prodId."  ");
print_r($results);

?>
问题回答

暂无回答




相关问题
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 ...

热门标签