dplsnw7329 2014-12-03 15:38
浏览 119
已采纳

在html中使用php来显示数据库

I am trying to create a table in a HTML Document using php, and here is my code:

<p>Below is the table of all the books available: <br />

<table border="1" ><th>Book ID</th><th>Subject</th><th>Title</th><th>Print Edition</th><th>Condition</th><th>Asking Price</th>


<?php 
    $server= 'MYSERVER';
    $user = 'MYUSERNAME';
    $password = 'MYPASSWORD';
    $database = 'MYDBNAME';
    $mysqli = new mysqli('server', 'user', 'password', 'database');
    foreach ( $mysqli->query('SELECT user,host FROM mysql.user') as $row ) 
    {?>
    <tr><td><?php echo $res['ID'];?></td><td><?php echo $res['Subject'];?></td><td><?php echo $res['Title'];?></td><td><?php echo $res['PrintEdition'];?></td><td><?php echo $res['Cond'];?></td><td><?php echo $res['Price'];?></td></tr>
<?php } 
mysqli_close($mysqli);
?>
</table>

<br />
If you like to request any of these titles, Do the following:

. . . .

However, it seems I'm not sure what is happening, but I am having this as the outcome on my Chrome (this is the actual screen shot of my webpage):


Below is the table of all the books available: query('SELECT * FROM entry_database') as $row ) {?> Book ID Subject Title Print Edition Condition Asking Price

(The above row looks like a table)

If you like to request any of these titles, Do the following:

I'm not sure why this is happening, but I have a hunch that it is because HTML treats the -> as a tag. Is there any way of fixing this?

Just to explain, I have looked at all the answers, tried all the answers, and as far as I am aware, I can't find the answer.

Many thanks in advance.

UPDATE 1:

So I managed to sort out the additional code showing, thanks to @Fred -ii-

However, the data is not showing. I tried the following to output the date, but no success:

foreach ( $mysqli->query('SELECT * FROM entry_database') as $row ) 
    {?>
    <?php echo $row['ID'];?><br /><?php echo $row['Subject'];?><br /><?php echo $row['Title'];?><br /><?php echo $row['PrintEdition'];?><br /><?php echo $row['Cond'];?><br /><?php echo $row['Price'];?><br />
<?php } 
mysqli_close($mysqli);
?>

We are getting there, I am sure

  • 写回答

4条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 fluent计算后处理中如何把质量分数和摩尔分数转化为体积分数
      • ¥20 asn1c编码问题,懂asn1的人很简单
      • ¥60 在排球比赛中,排球落于界限上时,人工判断存在一定的主观因素。利用图像处理的方法来计算排球落点相对界限中心位置,判断结果。
      • ¥15 使用vs2019开发的动态链路库在win7环境下使用有问题
      • ¥30 quartus prime画电路图,要发源文件和电路图每个模块批注,源程序和仿真结果
      • ¥15 MFC滚动条如何正确使用
      • ¥15 缓冲区算法求面积,基于文献
      • ¥50 电路PCB原理图设计AD19
      • ¥15 openstack 云平台搭建 创建实例错误
      • ¥15 联想笔记本网页加载突然出了问题不知道什么原因