如何在php表中获取mysql数据 [英] how get mysql data in php table

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

问题描述

浏览器窗口:

连接到MySQL

连接数据库



注意:未定义变量:link在C:\ xampp\htdocs \globall \ members.php第23行



警告:mysql_query()期望参数2为资源,给定为null在C:\ xampp\htdocs \globall \ members.php第23行





这是第23行

$ result = mysql_query($ query,$ link)



Browser window:
Connected to MySQL
Connected to Database

Notice: Undefined variable: link in C:\xampp\htdocs\globall\members.php on line 23

Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\globall\members.php on line 23


this is line 23
$result = mysql_query($query,$link)

<?php

mysql_connect("localhost", "admin", "") or die(mysql_error());



echo "Connected to MySQL<br />";

mysql_select_db("globall") or die(mysql_error());
echo "Connected to Database";

$query = " SELECT user_name,  mobile " .
        "FROM  customer ";


echo  "<br>" ;

$result = mysql_query($query,$link)
or die(mysql_error());

// this will count the total user in database
$num_users = mysql_num_rows($result);

$table_header =<<<EOD

<h2><center>GLoBALL Users Database </center></h2>

<table width="100%" border="1" cellpadding="2" cellspacing="2" align="center">
<tr>
<th>Username</th>
<th>Mobile</th>
</tr>

EOD;

$user_details = '';

while ($row = mysql_fetch_array($result)) {
$user_name = $row['user_name'];
$mobile = $row['mobile'];

$user_details .=<<<EOD

<tr>
<td>$user_name</td>
<td>$mobile</td>
</tr>
EOD;


$user_details .=<<<EOD

<tr>
<td>&nbsp;</td>
<td>Total : $num_users</td>
</tr>
EOD;
}
?>

推荐答案

result = mysql_query(
result = mysql_query(


查询,


链接)



link)

<?php

mysql_connect("localhost", "admin", "") or die(mysql_error());



echo "Connected to MySQL<br />";

mysql_select_db("globall") or die(mysql_error());
echo "Connected to Database";


这篇关于如何在php表中获取mysql数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆