在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()中。