如何使用LIKE关键字从Magento中的数据库中获取数据?

时间:2016-11-19 11:08:24

标签: php magento

我想要一个select查询,它使用"从"中获取数据。关键词 例如

select product name, image , description
from table where product name LIKE "'.$name'";

我想在Magento中了解如何从Magento中的数据库中获取此字段。我现有的查询是:

$sql = "
    SELECT value FROM catalog_product_entity_varchar
    WHERE entity_type_id = (
        SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product') AND attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product')
    )
";

现在联接查询是: -

<?php
$sql = " 
       SELECT p.entity_id , pv.value as name , pt.value as description , GROUP_CONCAT (DISTINCT ( cp.category_id ) SEPARATOR ', ') as categories , GROUP_CONCAT (DISTINCT (pm.value) SEPARATOR ', ') as imagesPath 
       FROM catalog_product_entity as p
       INNER JOIN catalog_product_entity_varchar as pv on pv.entity_id = p.entity_id  and   pv.attribute_id = 71
       INNER JOIN catalog_product_entity_text as pt on pt.entity_id = p.entity_id and pt.attribute_id = 72
       INNER JOIN catalog_category_product as cp on cp.product_id = p.entity_id
       LEFT JOIN catalog_product_entity_media_gallery as pm on pm.entity_id = p.entity_id and pm.attribute_id = 88
       GROUP BY cp.product_id , pm.entity_id " ;

   foreach($readConnection->fetchAll($sql) as $orders)
   {
   ?>   
      <?php echo $orders['name']; ?>
      <?php echo $orders['description']; ?>

 <?php
 }
 ?>

2 个答案:

答案 0 :(得分:0)

这是一个正确的代码,用于获取LIKE子句中项目的名称和描述 非常感谢@Halfer :)

$sql = SELECT p.`entity_id`, pv.`value` as name, pt.`value` as description 
FROM `catalog_product_entity` as p
INNER JOIN `catalog_product_entity_varchar` as pv on pv.`entity_id` = p.`entity_id` and     pv.`attribute_id` = 71
INNER JOIN `catalog_product_entity_text` as pt on pt.`entity_id` = p.`entity_id` and pt.`attribute_id` = 72
Where pv.value LIKE '%hp%';

答案 1 :(得分:0)

$sql_jacket = "SELECT entity_id FROM customer_entity where email
like '".$_REQUEST['useremail']."'";
$result_jacket = $conn->query($sql_jacket);
if ($result_jacket->num_rows > 0) 
{    
while($row_jacket = $result_jacket->fetch_assoc())
{
    $result1['user_status']=1;
}
}