【问题标题】:Programming a grid table php编写网格表 php
【发布时间】:2016-01-24 15:13:16
【问题描述】:

我有一个网格表(附上示例)。用户将在表单中输入宽度(列)和高度(行)。然后程序必须根据输入的数据输出价格,所以如果你看这个例子,如果宽度为 800,高度为 1000,价格将为 337。任何想法如何处理这个?我以前从来没有做过这样的事情。

我知道这是一个广泛的问题..但任何方向或教程将不胜感激。

【问题讨论】:

  • 看起来很简单,但请向我们展示您当前的数据网格 HTML 结构,以便我们提出与其直接相关的解决方案。

标签: php datagrid


【解决方案1】:

你需要这样的东西:

// price matrix: first index is y-axis, second is x-axis
$prices = [
    600 => [
        600 => 224,
        700 => 246,
        800 => 266,
        900 => 291,
        1000 => 313
    ],
    // here you put the rest...
];

//then echo the table;
echo "<table><tr>";
echo "<td></td>"; // first empty cell;
foreach ($prices[array_keys($prices)[0]] as $y_axis => $xprices){
    echo "<td>".$y_axis."</td>";
}
echo "</tr>";//finish setting up the header
foreach ($prices as $y_axis => $xprices) {
    echo "<tr>";
    echo "<td>".$y_axis."</td>";
    foreach($xprices as $y_axis=> $price){
        echo "<td>".$price."</td>";
    }
    echo "</tr>";
}
echo "</table>";

这更多是为了指导,希望能让你朝着正确的方向前进。

这会生成一个带有标题和第一行的表格:

<table>
    <tr>
        <td></td>
        <td>600</td>
        <td>700</td>
        <td>800</td>
        <td>900</td>
        <td>1000</td>
   </tr>
   <tr>
       <td>600</td>
       <td>224</td><td>246</td><td>266</td>
       <td>291</td><td>313</td>
   </tr>
</table>

在线 php 脚本:https://3v4l.org/BY45N(从此处获取 html)
Html代码评估器:http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro(并放在这里)

【讨论】:

  • 谢谢你,我会提供反馈:)
猜你喜欢
  • 1970-01-01
  • 2015-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多