本文介绍了如何从MySQL数据库获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有20记录的表(媒体),该记录有5列(ID,名称,电话,电子邮件,地址)我需要在我的php文件中显示这20条记录该怎么做?

I have table (media) having 20 record with 5 columns (id,name,phone,email,address)i need to show this 20 records in my php file how to do this?

推荐答案

了解如何使用PHP查询数据库,然后使用类似这样的查询从数据库中获取数据:

Learn how to query a database using PHP, then get data from the database using a query like:

SELECT * FROM media;

扩展解决方案:

$db = new mysqli('localhost', 'user', 'pass', 'demo');

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = "SELECT * FROM media;";

if(!$result = $db->query($sql)){
    die('There was an error running the query [' . $db->error . ']');
}

while($row = $result->fetch_assoc()){
    echo $row['id'] . ', ' . $row['name'] . ', ' . $row['phone'] . ', ' . $row['email'] . ', ' . $row['address'] . '<br />';
}

每个字段将在$row数组中用于earch结果行.

Each field will be available in the $row array for earch result row.

这篇关于如何从MySQL数据库获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 08:26