簡體   English   中英

我如何在PHP中回顯商品價格

[英]how can i echo item price in php

此代碼創建條形碼圖像並使用條形碼回顯商品名稱,但我想使用單價回顯商品名稱我該怎么辦,請幫助我解決此問題,謝謝

我在此代碼后編輯

$text = $item['name'];

像這樣

$text = $item['name'];

$text2 = $item['unit_price'];

但它無法正常工作的人可以告訴我什么問題以及如何解決

這是我的PHP條碼腳本

<head>
        <title><?php echo $this->lang->line('items_generate_barcodes'); ?></title>
    </head>
    <body>
    <table width='50%' align='center' cellpadding='20'>
    <tr>
    <?php 
    $count = 0;
    foreach($items as $item)
    {
        $barcode = $item['id'];

        $text = $item['name'];

        if ($count % 2 ==0 and $count!=0)
        {
            echo '</tr><tr>';
        }
        echo "<td><img src='".site_url()."/barcode?barcode=$barcode&text=$text&$text&width=256' /></td>";
        $count++;
    }
    ?>
    </tr>
    </table>
    </body>
    </html>

這是mysql結構

name            varchar(255)     latin1_swedish_ci          No                                   
category    varchar(255)    latin1_swedish_ci       No                                   
supplier_id int(11)         Yes NULL                                
item_number varchar(255)    latin1_swedish_ci       Yes NULL                                 
description varchar(255)    latin1_swedish_ci       No                                   
cost_price  double(15,2)            No                                  
unit_price  double(15,2)            No                                  
quantity    double(15,2)            No  0.00                                
reorder_level   double(15,2)            No  0.00                                
location    varchar(255)    latin1_swedish_ci       No                                   
item_id int(10)         No      auto_increment                          
allow_alt_description   tinyint(1)          No                                  
is_serialized   tinyint(1)          No                                  
deleted int(1)          No  0                               
expire

這是我的mysql條形碼功能

function generate_barcodes($item_ids)
{
    $result = array();

    $item_ids = explode(':', $item_ids);
    foreach ($item_ids as $item_id)
    {
        $item_info = $this->Item->get_info($item_id);

        $result[] = array('name' =>$item_info->name, 'id'=> $item_id);
    }

    $data['items'] = $result;
    $this->load->view("barcode_sheet", $data);
}

首先,您需要從數據庫的$item數組中獲得unit_price

在您的foreach循環中,替換以下行$text = $item['name']; 有了這個:

$text = $item['name'] . ' $' . number_format($item['unit_price'], 2);

代碼如下所示:

<head>
        <title><?php echo $this->lang->line('items_generate_barcodes'); ?></title>
    </head>
    <body>
    <table width='50%' align='center' cellpadding='20'>
    <tr>
    <?php 
    $count = 0;
    foreach($items as $item)
    {
        $barcode = $item['id'];

        $text = $item['name'] . ' $' . number_format($item['unit_price'], 2);

        if ($count % 2 ==0 and $count!=0)
        {
            echo '</tr><tr>';
        }
        echo "<td><img src='".site_url()."/barcode?barcode=$barcode&text=$text&$text&width=256' /></td>";
        $count++;
    }
    ?>
    </tr>
    </table>
    </body>
    </html>

我強烈感覺到您的SELECT語句缺少unit_price列。 請向我們顯示填充$ items數組的SELECT語句。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM