douyan9398 2015-11-02 03:14
浏览 45
已采纳

打印表时Php未定义的偏移错误

I'm tried to call the variable but I get this error Notice: Undefined offset: 6 in /Applications/XAMPP/xamppfiles/htdocs/databasetwo/untitled.php on line 113

This code print a table to Html I want to do it programmatically so the array can print the amount selected.

$id = "table" ;
// echo "<table id=$id><tr><th>Title</th><th>Price</th><th>Number</th></tr>";
echo "<table id=$id>";
foreach($rows as $row){
    echo "<tr>";
        for ($i = 0 ; $i <= $amount ; $i++) {
        echo "<td>{$row[$i]}</td>";
        /*echo "<td>{$row[1]}</td>";
        echo "<td>{$row[2]}</td>";
        echo "<td>{$row[3]}</td>";
        echo "<td>{$row[4]}</td>";
        echo "<td>{$row[5]}</td>";
        echo "<td>{$row[6]}</td>"; */

}

    echo "</tr>";
}
echo "</table>";

If I leave it $row[0], 1, 2 etc. Will Work. The error I'm getting is Notice: Undefined offset: 6 in /Applications/XAMPP/xamppfiles/htdocs/databasetwo/untitled.php on line 113

  • 写回答

1条回答 默认 最新

  • douyasihefu6214 2015-11-02 03:17
    关注

    If you are starting from 0, make sure for ending criteria you add value - 1.

    for ($i = 0 ; $i <= $amount - 1 ; $i++) {
    

    Or remove = in loop like this,

    for ($i = 0 ; $i < $amount ; $i++) {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog