【问题标题】:how can i echo item price in php我如何在php中回显商品价格
【发布时间】:2013-06-08 13:16:30
【问题描述】:

此代码创建条形码图像并使用条形码回显项目名称 但我想用单价回显项目名称 我该怎么做请帮我解决这个问题 谢谢

我在这段代码之后编辑

$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_price通过查询你的阅读数据来自
  • 是的,我在 item_price 中有数据

标签: php mysql barcode


【解决方案1】:

首先,您需要在数据库中的$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>

【讨论】:

  • 亲爱的我更新并检查它然后显示错误不允许的关键字符和图像也没有显示条形码
  • url 显示如下 index.php/barcode?barcode=1&text=Laptop%20$0.00&Laptop%20$0.00&width=256 并且单价未出现在 url 中,请参阅 %20$0.00&
【解决方案2】:

我有强烈的感觉,您的 SELECT 语句缺少 unit_price 列。 请向我们展示填充 $items 数组的 SELECT 语句。

【讨论】:

  • 函数 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); } 这是我的选择语句,我想我怎样才能在其中编辑 unit_price
猜你喜欢
  • 2013-10-19
  • 1970-01-01
  • 2014-05-02
  • 1970-01-01
  • 2022-12-13
  • 1970-01-01
  • 2016-03-25
  • 2019-04-30
  • 1970-01-01
相关资源
最近更新 更多