0

Hello everyone I need to fetch rows and display them. This is not a aproblem, but! I have column icon, which contains the url of the icon, so I should display the image from the url. Could you tell me how to display that image?

  <?php

    global $wpdb;
    // this adds the prefix which is set by the user upon instillation of 
    wordpress
    $table_name = $wpdb->prefix . "tablename";
    // this will get the data from your table
    $retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name" );
    ?>
    <ul>
        <?php
        foreach ($retrieve_data as $retrieved_data){ ?>


      <div class="innerApp">
        //THIS IS THE PROBLEMATIC LINE
        <img  class="appLogo" src="<?php bloginfo('template_url') ?><?php 
       echo $retrieved_data->icon?>">   
        <p class="justTextTextApp"><?php echo $retrieved_data->NAME?></p>
        <p class="justDescription"><?php echo $retrieved_data->description?>
        </p>
      </div>

        <?php 
                                                   }
        ?>
       </ul>
6
  • what is url of your image? how does it related to page? does it static or dinamic? Commented Jan 31, 2018 at 9:17
  • The url is just the place from where the image is derieved. It has no relation with the page. So basically, we have url(the icon url) and I assume I should use it as src"" in my <img>. But the table is custom, so I am not sure which function I can use. Commented Jan 31, 2018 at 9:23
  • does $retrieve_data contain your image url? Commented Jan 31, 2018 at 9:25
  • my url is in $retrieved_data->icon Commented Jan 31, 2018 at 9:29
  • 1
    then why do you use bloginfo('template_url')? Commented Jan 31, 2018 at 9:32

1 Answer 1

1

I'd highly recommend to escape all values before output, e.g. echo esc_html( $retrieved_data->NAME ).

The same for the image:

<img src="<?php echo esc_url( $retrieved_data->icon ); ?>" />

You can read more about Securing Output in the developer handbook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.