dpb42021 2018-08-11 18:07
浏览 44

将Myscho Echo转换成表格 - 演示文稿和DOM

Two questions in one: First question, mainly about presentation: I'm echo-ing the following code which should create a table. The table should have a single column, but it's being rendered with the elements above the image as a single line. can anyone see why?

<?php   
$sql = "SELECT * FROM catdata WHERE featured='yes' LIMIT 2";
if($result = mysqli_query($link, $sql)){
    if(mysqli_num_rows($result) > 0){
        echo "<table>";
        while($row = mysqli_fetch_array($result)){
            echo "<tr>";
                echo "<td>" . $row['manufacturer'] . "</td>";
            echo "</tr";

            echo "<tr>";
                echo "<td>" . $row['title'] . "</td>";
            echo "</tr";

            echo "<tr>";

                echo "<td><img src=\"6.diesel.png\"></td>";
            echo "</tr>";

            echo "<tr>";    
                echo "<td>" . $row['size'] . "l</td>";
            echo "</tr>";
            echo "<tr>";
                echo "<td>" . $row['mileage'] . "</td>";
            echo "</tr>";
            echo "<tr>";
                echo "<td>" . $row['fitsmodel'] . "</td>";
            echo "</tr>";
            echo "<tr class=\"tablePriceBlock\">";
                echo "<td>£" . $row['pricefitted'] . "</td>";
            echo "</tr>";
            echo "<tr>";
                echo "<td>£" . $row['pricedel'] . "</td>";

            echo "</tr>";
        }
        echo "</table>";
        // Free result set
        mysqli_free_result($result);
    } else {
            echo "No records matching your query were found.";
            }
} else{
            echo "ERROR: Unable to execute $sql. " . mysqli_error($link);
    }
?>

Question 2:

Can I show the second result in a second column, or as a separate table? Also, is it possible to access the $result elements like say, $[manufacturer][1]?

  • 写回答

2条回答 默认 最新

  • dorisdong0514 2018-08-11 19:18
    关注

    Always look at the emitted source your code generates by either "View Source" or using a tool like curl. You'll find this mistake:

    echo "</tr";
    

    You're missing a >.

    Many people who write HTML have browser plugins that can link through to an HTML validator to ensure they've got the correct syntax. You may want to find and install one of these.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法