admin管理员组文章数量:1277910
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>
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>
Share
Improve this question
asked Jan 31, 2018 at 9:10
AlisonVilmoreVAlisonVilmoreV
131 silver badge4 bronze badges
6
|
Show 1 more comment
1 Answer
Reset to default 1I'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.
本文标签: phpHow to get image from url from the database
版权声明:本文标题:php - How to get image from url from the database? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741265437a2368374.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$retrieve_data
contain your image url? – Samvel Aleqsanyan Commented Jan 31, 2018 at 9:25bloginfo('template_url')
? – Samvel Aleqsanyan Commented Jan 31, 2018 at 9:32