douyan8070 2017-04-06 03:20
浏览 42
已采纳

将循环编号附加到SQL行变量

"Undefined variable: payout_item_1" so it's getting the variable name correctly but I must have the format wrong.

for ($x = 1; $x <= 5; $x++) {
    echo "<input name = 'payout_item_" . $x . "' type = 'text' value = '" . $row[${"payout_item_" . $x}] . "' style = 'width : 150px;' ";
} 
  • 写回答

1条回答 默认 最新

  • dsxi70423 2017-04-06 03:33
    关注

    I'm making a couple assumptions

    1. You have a table with columns "payout_item_1" through "payout_item_5"
    2. You do not have variables called $payout_item_1 through $payout_item_5 in which the actual column names are stored.

    Currently your code is building variable variables:

    This statement builds a variable name with payout_item_1 (in the first iteration). Effectively $payout_item_1.

    ${"payout_item_" . $x}
    

    The code is then looking for a value in that variable to use as the column header name. Effectively, it's expecting somewhere further up for there to be something akin to

    $payout_item_1 = "column1";
    

    Which, as the error suggests, it cannot find. If my assumption in 1. was correct, all you need to do is reformat to

    $row["payout_item_" . $x]
    

    and you will be referencing the column payout_item_1 (through 5) from your $row object. Written literally:

    $row["payout_item_1"]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分