【问题标题】:Mysql and php w/ html database issueMysql 和 php w/html 数据库问题
【发布时间】:2017-01-05 05:59:45
【问题描述】:

我想从我的 sql 数据库中获取数据到一个带有 html 的表中。

我已经编写了以?>结尾的第一部分代码

以html表格开始,以html结束

我的代码只获取空表而没有从我的数据库中获取数据,这里是代码,我不知道如何使用它获取数据

 <td> 
   <?php echo $result['nazwiskoimie'] ?>
 </td>

这是完整的代码:

<?php
  $con=mysqli_connect("localhost","root","","listap");

  if (mysqli_connect_errno()) {
    echo "Blad przy polaczeniu z baza: " . mysqli_connect_error();
  }

  $result = mysqli_query($con,"SELECT * FROM 'lista'");                     
?>

<html> 

  <table border='1'>
    <tr>
    </tr>
    <tr>
      <td> <?php echo $result['nazwiskoimie'] ?> </td>
      //in this part have problem to get my data from database 
</html>

这里还有一个结果的截图:Final After a Save my file

【问题讨论】:

  • 您似乎对如何与数据库交互缺乏基本的了解,请谷歌上有关“如何从 mysql 数据库中检索数据”的教程
  • 提供有关 sn-p 的清晰文档。你的 sn-p 看起来很垃圾。 :(
  • 我从 1 个月前开始学习 php 和 mysql,我不是专家 :D

标签: php html mysql database mysqli


【解决方案1】:

请试试这个:

$result = mysqli_query($con,"SELECT * FROM lista");;
?>
<html> 

<table border='1'>

<?php

if (mysqli_num_rows($result) > 0) {
// output data of each row
 while($row = mysqli_fetch_assoc($result)) {
?>
<tr>
   <td><?php echo $row['nazwiskoimie']?></td>
</tr>
 <?php
 }
} ?>
</table>
</html>

【讨论】:

  • ( ! ) 警告:mysqli_num_rows() 期望参数 1 为 mysqli_result,布尔值在 C:\wamp\www\mysqlnauka\listap.php 第 17 行第 17 行中给出: if (mysqli_num_rows($result ) > 0) {
  • 更改 $result = $result = mysqli_query($con,"SELECT * FROM 'lista'"); to $result = $result = mysqli_query($con,"SELECT * FROM lista");
  • 谢谢老兄!它工作+1 :)
猜你喜欢
  • 2011-02-13
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多