Magento 2 - Hide Products with no Images via PHP SQL QueryHow to make SQL query with MagentoComplex SQL query to MagentoUpdate weight through sql queryHelp building an SQL query for products with custom optionsConvert SQL Select to Magento SQL queryMagento SQL Insert query is not working and shows no errorssql to query to Magento querySql Query Not Working in DBSQL Query for gettin all products with custom optionsSlow SQL query with many joins

Parse a C++14 integer literal

Is being an extrovert a necessary condition to be a manager?

Is there any official Lore on Keraptis the Wizard, apart from what is in White Plume Mountain?

How was the blinking terminal cursor invented?

Cycling to work - 30 mile return

Precedent for disabled Kings

Latin words remembered from high school 50 years ago

Germany rejected my entry to Schengen countries

How to plot a surface from a system of equations?

Why would Thor need to strike a building with lightning to attack enemies?

Have the writers and actors of Game Of Thrones responded to its poor reception?

Why didn't Daenerys' advisers suggest assassinating Cersei?

Can the bitcoin lightning network support more than 8 decimal places?

What were the "pills" that were added to solid waste in Apollo 7?

Is it a good idea to teach algorithm courses using pseudocode instead of a real programming language?

Addressing an email

How do you cope with rejection?

Why is python script running in background consuming 100 % CPU?

Isn't Kirchhoff's junction law a violation of conservation of charge?

How to choose the correct exposure for flower photography?

Hotel booking: Why is Agoda much cheaper than booking.com?

Why does string strummed with finger sound different from the one strummed with pick?

In How Many Ways Can We Partition a Set Into Smaller Subsets So The Sum of the Numbers In Each Subset Is Equal?

Bash Array of Word-Splitting Headaches



Magento 2 - Hide Products with no Images via PHP SQL Query


How to make SQL query with MagentoComplex SQL query to MagentoUpdate weight through sql queryHelp building an SQL query for products with custom optionsConvert SQL Select to Magento SQL queryMagento SQL Insert query is not working and shows no errorssql to query to Magento querySql Query Not Working in DBSQL Query for gettin all products with custom optionsSlow SQL query with many joins






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have an SQL query that i run on the database manually which checks the catalogue for products that do not have an image and hides them, i want to run this via cron so have created a php with the following content:



 <?php 

$servername = "localhost";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";

// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);

// Check connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);


// Script to run

$sql=

update catalog_product_entity_int m;
left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
set value = 2
where
a.attribute_code = 'status'
and m.entity_id in
(
select m.entity_id
from catalog_product_entity m
left join catalog_product_entity_media_gallery_value_to_entity a
on a.entity_id = m.entity_id
where a.value_id is null
)
;

if ($conn->query($sql) === TRUE)
echo "Record updated successfully";
else
echo "Error updating record: " . $conn->error;


$conn->close();

?>


But I get this error: [PHP Parse error: syntax error, unexpected 'catalog_product_entity_int' (T_STRING) in /home/public_html/modimages/hideimages.php on line 20



The query works fine when i put it directly on phpmyadmin so i am guessing i am missing something very simple.










share|improve this question




























    0















    I have an SQL query that i run on the database manually which checks the catalogue for products that do not have an image and hides them, i want to run this via cron so have created a php with the following content:



     <?php 

    $servername = "localhost";
    $username = "xxx";
    $password = "xxx";
    $dbname = "xxx";

    // Create connection
    $conn = new mysqli($servername, $username, $password,$dbname);

    // Check connection
    if ($conn->connect_error)
    die("Connection failed: " . $conn->connect_error);


    // Script to run

    $sql=

    update catalog_product_entity_int m;
    left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
    set value = 2
    where
    a.attribute_code = 'status'
    and m.entity_id in
    (
    select m.entity_id
    from catalog_product_entity m
    left join catalog_product_entity_media_gallery_value_to_entity a
    on a.entity_id = m.entity_id
    where a.value_id is null
    )
    ;

    if ($conn->query($sql) === TRUE)
    echo "Record updated successfully";
    else
    echo "Error updating record: " . $conn->error;


    $conn->close();

    ?>


    But I get this error: [PHP Parse error: syntax error, unexpected 'catalog_product_entity_int' (T_STRING) in /home/public_html/modimages/hideimages.php on line 20



    The query works fine when i put it directly on phpmyadmin so i am guessing i am missing something very simple.










    share|improve this question
























      0












      0








      0








      I have an SQL query that i run on the database manually which checks the catalogue for products that do not have an image and hides them, i want to run this via cron so have created a php with the following content:



       <?php 

      $servername = "localhost";
      $username = "xxx";
      $password = "xxx";
      $dbname = "xxx";

      // Create connection
      $conn = new mysqli($servername, $username, $password,$dbname);

      // Check connection
      if ($conn->connect_error)
      die("Connection failed: " . $conn->connect_error);


      // Script to run

      $sql=

      update catalog_product_entity_int m;
      left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
      set value = 2
      where
      a.attribute_code = 'status'
      and m.entity_id in
      (
      select m.entity_id
      from catalog_product_entity m
      left join catalog_product_entity_media_gallery_value_to_entity a
      on a.entity_id = m.entity_id
      where a.value_id is null
      )
      ;

      if ($conn->query($sql) === TRUE)
      echo "Record updated successfully";
      else
      echo "Error updating record: " . $conn->error;


      $conn->close();

      ?>


      But I get this error: [PHP Parse error: syntax error, unexpected 'catalog_product_entity_int' (T_STRING) in /home/public_html/modimages/hideimages.php on line 20



      The query works fine when i put it directly on phpmyadmin so i am guessing i am missing something very simple.










      share|improve this question














      I have an SQL query that i run on the database manually which checks the catalogue for products that do not have an image and hides them, i want to run this via cron so have created a php with the following content:



       <?php 

      $servername = "localhost";
      $username = "xxx";
      $password = "xxx";
      $dbname = "xxx";

      // Create connection
      $conn = new mysqli($servername, $username, $password,$dbname);

      // Check connection
      if ($conn->connect_error)
      die("Connection failed: " . $conn->connect_error);


      // Script to run

      $sql=

      update catalog_product_entity_int m;
      left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
      set value = 2
      where
      a.attribute_code = 'status'
      and m.entity_id in
      (
      select m.entity_id
      from catalog_product_entity m
      left join catalog_product_entity_media_gallery_value_to_entity a
      on a.entity_id = m.entity_id
      where a.value_id is null
      )
      ;

      if ($conn->query($sql) === TRUE)
      echo "Record updated successfully";
      else
      echo "Error updating record: " . $conn->error;


      $conn->close();

      ?>


      But I get this error: [PHP Parse error: syntax error, unexpected 'catalog_product_entity_int' (T_STRING) in /home/public_html/modimages/hideimages.php on line 20



      The query works fine when i put it directly on phpmyadmin so i am guessing i am missing something very simple.







      magento2 php sql






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 13 at 15:00









      Mehdi RafiaiMehdi Rafiai

      111117




      111117




















          1 Answer
          1






          active

          oldest

          votes


















          1














          You missed the quotes (") in variable $sql. Try the below one.



          $sql= "update catalog_product_entity_int m
          left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
          set value = 2
          where
          a.attribute_code = 'status'
          and m.entity_id in
          (
          select m.entity_id
          from catalog_product_entity m
          left join catalog_product_entity_media_gallery_value_to_entity a
          on a.entity_id = m.entity_id
          where a.value_id is null
          )";





          share|improve this answer























          • Worked perfectly, thank you!

            – Mehdi Rafiai
            May 13 at 15:55











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f274379%2fmagento-2-hide-products-with-no-images-via-php-sql-query%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You missed the quotes (") in variable $sql. Try the below one.



          $sql= "update catalog_product_entity_int m
          left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
          set value = 2
          where
          a.attribute_code = 'status'
          and m.entity_id in
          (
          select m.entity_id
          from catalog_product_entity m
          left join catalog_product_entity_media_gallery_value_to_entity a
          on a.entity_id = m.entity_id
          where a.value_id is null
          )";





          share|improve this answer























          • Worked perfectly, thank you!

            – Mehdi Rafiai
            May 13 at 15:55















          1














          You missed the quotes (") in variable $sql. Try the below one.



          $sql= "update catalog_product_entity_int m
          left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
          set value = 2
          where
          a.attribute_code = 'status'
          and m.entity_id in
          (
          select m.entity_id
          from catalog_product_entity m
          left join catalog_product_entity_media_gallery_value_to_entity a
          on a.entity_id = m.entity_id
          where a.value_id is null
          )";





          share|improve this answer























          • Worked perfectly, thank you!

            – Mehdi Rafiai
            May 13 at 15:55













          1












          1








          1







          You missed the quotes (") in variable $sql. Try the below one.



          $sql= "update catalog_product_entity_int m
          left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
          set value = 2
          where
          a.attribute_code = 'status'
          and m.entity_id in
          (
          select m.entity_id
          from catalog_product_entity m
          left join catalog_product_entity_media_gallery_value_to_entity a
          on a.entity_id = m.entity_id
          where a.value_id is null
          )";





          share|improve this answer













          You missed the quotes (") in variable $sql. Try the below one.



          $sql= "update catalog_product_entity_int m
          left join eav_attribute a on a.entity_type_id = 4 and a.attribute_id = m.attribute_id
          set value = 2
          where
          a.attribute_code = 'status'
          and m.entity_id in
          (
          select m.entity_id
          from catalog_product_entity m
          left join catalog_product_entity_media_gallery_value_to_entity a
          on a.entity_id = m.entity_id
          where a.value_id is null
          )";






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 13 at 15:27









          Bilal UseanBilal Usean

          5,32544094




          5,32544094












          • Worked perfectly, thank you!

            – Mehdi Rafiai
            May 13 at 15:55

















          • Worked perfectly, thank you!

            – Mehdi Rafiai
            May 13 at 15:55
















          Worked perfectly, thank you!

          – Mehdi Rafiai
          May 13 at 15:55





          Worked perfectly, thank you!

          – Mehdi Rafiai
          May 13 at 15:55

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f274379%2fmagento-2-hide-products-with-no-images-via-php-sql-query%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form