如何用 Doctrine 翻译这个查询?

发布于 2024-10-10 10:55:16 字数 372 浏览 0 评论 0原文

我尝试生成自定义查询(我正在为网站开发搜索引擎)。

这是要翻译的查询:

SELECT *  FROM `offre_habitation` 
WHERE `id_type_offre` = 2 
AND `id_nature_offre` = 1 
AND (`nb_pieces` = 2 or `nb_pieces` = 1 or `nb_pieces` = 3 or `nb_pieces` = 4)
AND (`id_secteur`=1 OR `id_secteur` = 2 or id_secteur = 3) 
AND `surface_habitable` > 90 
AND `prix` > 700

你能帮我吗?

I try to generate a custom query (I'm developing a search engine for a website).

This is te query to translate :

SELECT *  FROM `offre_habitation` 
WHERE `id_type_offre` = 2 
AND `id_nature_offre` = 1 
AND (`nb_pieces` = 2 or `nb_pieces` = 1 or `nb_pieces` = 3 or `nb_pieces` = 4)
AND (`id_secteur`=1 OR `id_secteur` = 2 or id_secteur = 3) 
AND `surface_habitable` > 90 
AND `prix` > 700

Could you help me please ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若相惜即相离 2024-10-17 10:55:16

未经测试,但类似这样的东西应该可以解决问题:

$q = Doctrine_Query::create()
  ->select('o.*')
  ->from('offre_habitation o')
  ->where('o.id_type_offre = ?', 2)
  ->andWhere('o.id_nature_offre = ?', 1)
  ->andWhereIn('o.nb_pieces', array(1, 2, 3, 4))
  ->andWhereIn('o.id_secteur', array(1, 2, 3))
  ->andWhere('o.surface_habitable > ?', 90)
  ->andWhere('o.prix > ?', 700);

// Test:
echo $q->getSqlQuery();

...这利用了这样一个事实:例如:

AND (`id_secteur`=1 OR `id_secteur` = 2 or id_secteur = 3) 

...与以下内容相同:

AND `id_secteur` IN (1, 2, 3)

Not tested, but something like this should do the trick:

$q = Doctrine_Query::create()
  ->select('o.*')
  ->from('offre_habitation o')
  ->where('o.id_type_offre = ?', 2)
  ->andWhere('o.id_nature_offre = ?', 1)
  ->andWhereIn('o.nb_pieces', array(1, 2, 3, 4))
  ->andWhereIn('o.id_secteur', array(1, 2, 3))
  ->andWhere('o.surface_habitable > ?', 90)
  ->andWhere('o.prix > ?', 700);

// Test:
echo $q->getSqlQuery();

...this makes use of the fact that, for example:

AND (`id_secteur`=1 OR `id_secteur` = 2 or id_secteur = 3) 

...is the same as:

AND `id_secteur` IN (1, 2, 3)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文