Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
¿Cómo muestro una imagen después de haber hecho su selección con una matriz php?

Mi pregunta es, ¿cuál sería la mejor manera de hacerlo?

 <? 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 answers
Answer question

0

El método general que usaría es

  • alguien hace clic en el producto que llama a una función javascript
  • su javascript hace una llamada ajax a su script PHP en el back-end
  • su secuencia de comandos php obtiene los datos y los repite como una cadena codificada JSON
  • su javascript obtiene estos nuevos datos, los analiza en JSON y hace que aparezca la imagen

Usando php, construyes tu página html inicial. Digamos que tiene un elemento de imagen para mostrar la imagen seleccionada, como:

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

Use algo como la identificación del producto como argumento para la función que se llama desde el botón

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

Su función JS se vería así

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

Su página PHP myBackendPHPendpoint.php se vería así

 <?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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!