Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

276
Visualizações
How do I display an image after you've made your selection with a php Array?

My question is, what would be the best way to go about this?

<?
if (in_array("1434", $category)) {
  if($item > 0) {
    $wc_product = wc_get_product($item);
    echo '<img src="' . get_the_post_thumbnail_url($item, 'medium') . '">'; 
  }
}
?>

[1]:

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The general method that you would use is

  • someone clicks on the product which calls a javascript function
  • your javascript makes an ajax call to your PHP script on the back end
  • your php script gets the data and echoes it back as a JSON encoded string
  • your javascript gets this new data, parses into JSON and makes the image appear

Using php, you build your initial html page. Lets say you have an image element to show the selected image, like:

<img id='mainImg' src='/placeholder-image.jpg' />

Use something like the product id as the argument for the function that is called from the button

<button onclick='getProductData(1234)'>View Product</button>

Your JS function would look something like this

function getProductData(id) {
   let url = '/myBackendPHPendpoint.php?pid=' + id
   $.ajax({url: url,
        success: function(json){
          json = JSON.decode(json)
          $('#mainImg').attr('src', json.image)
        }
    })
}

Your PHP page myBackendPHPendpoint.php would look something like

<?php
  $id = $_GET['pid'];
  // database query to get the product data
  // get the result as an object or array in php  
  echo json_encode($result);
?>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda