Php 从另一个数据库中定义的sku查询产品图像
我在wordpress/woocommerce服务器中创建了一个单独的mySQL数据库,它保存着单独的数据。我使用此表查看客户的基本帐户历史记录 其中一列的字符串数据与我的商业商店中产品的SKU相同。我想做的是将产品的缩略图放在动态php表中SKU旁边。我的定制表如下所示Php 从另一个数据库中定义的sku查询产品图像,php,mysql,wordpress,image,woocommerce,Php,Mysql,Wordpress,Image,Woocommerce,我在wordpress/woocommerce服务器中创建了一个单独的mySQL数据库,它保存着单独的数据。我使用此表查看客户的基本帐户历史记录 其中一列的字符串数据与我的商业商店中产品的SKU相同。我想做的是将产品的缩略图放在动态php表中SKU旁边。我的定制表如下所示 item | SKU | Amount dog | SKU1 | 3 cat | SKU2 | 4 当我在php表中调用它时;看起来是这样的: SKU | Item | Amount SKU1 | dog | 3 SKU2
item | SKU | Amount
dog | SKU1 | 3
cat | SKU2 | 4
当我在php表中调用它时;看起来是这样的:
SKU | Item | Amount
SKU1 | dog | 3
SKU2 | cat | 4
我希望产品图像位于SKU1
之前;因此:
(image)SKU1 | dog | 3
这是我尝试过的(抓取帖子id获取产品图片),但似乎不起作用
$result = mysqli_query($con,"SELECT * FROM wp_payout_history WHERE user=$userid ORDER BY date DESC");
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
$SKU = $row['SKU']
$post_id = wc_get_product_id_by_sku($SKU);
$product_meta = get_post_meta($post_id);
$image = wp_get_attachment_image( $product_meta['_thumbnail_id'][0]), 'full' );
echo "<td> ". $image . "" . $row['SKU'] . "</td>";
echo "<td>" . $row['amount'] . "</td>";
$result=mysqli\u query($con,“从wp\u支付历史中选择*,其中user=$userid ORDER BY date DESC”);
while($row=mysqli\u fetch\u数组($result))
{
回声“;
$SKU=$row['SKU']
$post_id=wc_get_product_id_by_sku($sku);
$product\U meta=get\U post\U meta($post\U id);
$image=wp_-get_-attachment_-image($product_-meta[''缩略图id'][0]),'full');
回显“$image.”“$row['SKU']”;
回显“$row['amount']”;
首先,尝试使用$wpdb
,最好是练习IMHO
更改:
$product_meta = get_post_meta($post_id);
$image = wp_get_attachment_image( $product_meta['_thumbnail_id'][0]), 'full' );
$thumb_id = get_post_thumbnail_id($post_id);
$image = wp_get_attachment_image( $thumb_id, 'full' );
进入:
$product_meta = get_post_meta($post_id);
$image = wp_get_attachment_image( $product_meta['_thumbnail_id'][0]), 'full' );
$thumb_id = get_post_thumbnail_id($post_id);
$image = wp_get_attachment_image( $thumb_id, 'full' );
如果这不起作用,请检查$post\u id
是否存在,以及它是否有post缩略图