Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中显示mysql的数据结果_Php_Mysql - Fatal编程技术网

在php中显示mysql的数据结果

在php中显示mysql的数据结果,php,mysql,Php,Mysql,我需要显示数据库中的公司名称,但此代码不适用于我。请帮忙。谢谢 <?php // connect to the database include('php/db.php'); $result = mysql_query("select name from company where company_id = 1"); echo $result['name']; ?> 尝试以下代码: while($row = mysql_fetch_array($result)

我需要显示数据库中的公司名称,但此代码不适用于我。请帮忙。谢谢

<?php

// connect to the database
include('php/db.php');

   $result = mysql_query("select name from company where company_id = 1");


 echo $result['name'];
 ?>

尝试以下代码:

 while($row = mysql_fetch_array($result))
  {
   echo ""+$row['name'];
   echo "<br>";
  }
while($row=mysql\u fetch\u array($result))
{
echo“+$row['name'];
回声“
”; }
mysql\u query
返回一个对象,首先需要使用
mysql\u fetch\u assoc()将该对象转换为关联数组

然后可以使用所使用的方法访问该数组的元素


您可能想看看如何使用
mysqli
函数,因为
mysql
函数会贬值。

试试这一个

// connect to the database
include('php/db.php');
$result = mysql_query("select name from company where company_id='1'");
while($row = mysql_fetch_array($result))
{
      echo $row['name']."<br>";
}
//连接到数据库
包括('php/db.php');
$result=mysql_query(“从公司中选择名称,公司id='1'”);
while($row=mysql\u fetch\u数组($result))
{
echo$row['name']。“
”; }
是的,让我用魔法找出你数据库中的内容。嗯,顺便问一下,你的
mysql\u fetch\u array()
在哪里?我的代码现在看起来像这样,但没有任何结果:我尝试了代码,没有任何结果。您可以在www.bigbossfood.com/companyname.php上看到结果还有其他想法吗?另一个方法是,您可以使用mysql\u fetch\u assoc返回正确的对象,然后您可以在尝试使用foreach循环显示后将数据存储到array()中。