Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用LIKE关键字从Magento中的数据库中获取数据?_Php_Magento - Fatal编程技术网

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

Php 如何使用LIKE关键字从Magento中的数据库中获取数据?,php,magento,Php,Magento,我想要一个select查询,它使用like关键字从数据库中获取数据 例如 我想在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 = 'c

我想要一个select查询,它使用like关键字从数据库中获取数据 例如

我想在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
 }
 ?>

这是获取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%';

这看起来像SQL,中间有一些PHP。假设您想在PHP中实现这一点,那么到目前为止您有哪些PHP?你试过什么,有什么问题吗?注意,您可能希望使用参数绑定-在您的示例中,您可能会遇到SQL注入漏洞。首先感谢您纠正我的错误:您是对的,这是一个带有php变量的SQL查询,我不想在php中执行此操作,我只想在Magento中查询如何使用like子句从数据库中获取数据。我有一个Magento查询,它从数据库中获取所有产品名称,但我不明白在该查询中应该将like子句放在哪里。查询为:$sql=从目录\产品\实体\ varchar中选择值,其中实体\类型\ id=从eav\实体\类型中选择实体\类型\ id,其中实体\类型\代码='catalog\产品',属性\ id=从eav\属性中选择属性\ id,其中属性\代码='name',实体\类型\ id=从eav\实体\类型中选择实体\ id实体类型代码='目录产品';我已经在你的问题中添加了这一点。你会花一些时间用换行符重新格式化它,使其可读吗?哈哈哈,是的,你现在正在处理图像..:D
$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%';
$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;
}
}