假設我有一個名爲mytable的與列的表:函數返回的查詢結果
------------------------
| id | field1 | field2 |
------------------------
,並假設我有一個HTML文件:
<body>
<?php
include ('connect-db.php');
include ('function.php');
?>
<ul>
<?php
myfunction();
while($row = $result->fetch_assoc()){
echo "<li>".$row['field1']." and ". $row[field2]."</li>";
}
?>
</ul>
</body>
這是我的connect-db.php
文件:
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "dbname";
$conn=new mysqli($servername, $username, $password, $dbname);
?>
這是我的function.php
文件:
<?php
function myfunction(){
$sql = "SELECT * FROM mytable";
$result = $conn->query($sql);
}
?>
如何回顯字段1和字段2?因爲我有和錯誤
提供你的錯誤,請 – demo