doupu1727 2016-10-26 15:45
浏览 59
已采纳

从MySQL列获取数组

I'm storing an array of comma separated values in my database in a column called line_services. The data in the column looks like 1,1,1,1,0,0,0 and I have a prepared statement where I bind the results of this column to the variable $line_services. In this prepared statement I have the following code after my fetch.

foreach(explode(',', $line_services) as $lineservices) {
    if ($lineservices == '1') {
        strtolower(str_replace('','_',$service_name.'_total')) = ((($service_tax / 100) * $service_cost) + 80.00) * $line_artwork_hours;  //1 hour
    }
    if ($lineservices == '2') {
        strtolower(str_replace('','_',$service_name.'_total')) = ((($service_tax / 100) * $material_cost) + $material_cost) * $line_product_sqft; //2 sq ft
    }    
    if ($lineservices == '3') {
        strtolower(str_replace('','_',$service_name.'_total')) = (($service_tax / 100) * ($line_L + $line_W)) + ($line_L + $line_W); //3 linear
    } 
    if ($lineservices == '4') {
        strtolower(str_replace('','_',$service_name.'_total')) = (($service_tax / 100) * (($line_L + $line_W) * 2) * .75) + (($line_L + $line_W) * 2) * .75; //4 linear
    } 
}

I'm getting the following error:

Can't use function return value in write context

When I do a var_dump on $line_services it is coming up NULL even though there is data in the column. The line_services column in the database is a varchar if that makes any difference.

  • 写回答

3条回答 默认 最新

  • doulu8415 2016-10-26 16:00
    关注

    I assume you are trying for a variable variables? Rarely if ever a good idea, but you can use the curly syntax:

    ${strtolower(str_replace('','_',$service_name.'_total'))} = 'whatever'; 
    

    Consider using an array instead:

    $total[$service_name] = 'whatever';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作