Php 从数据库中检索数据并将其写入html页面
我正在尝试使用php从mysql数据库检索数据,并将数据写入html网页。但我看到的都是空白,它什么也没写,我也找不到错误在哪里。我更改了localhost phpMyadmin的密码,所以这不会是错误的。我也没有收到任何无法连接到数据库的错误 这是我的密码:Php 从数据库中检索数据并将其写入html页面,php,html,mysql,database,Php,Html,Mysql,Database,我正在尝试使用php从mysql数据库检索数据,并将数据写入html网页。但我看到的都是空白,它什么也没写,我也找不到错误在哪里。我更改了localhost phpMyadmin的密码,所以这不会是错误的。我也没有收到任何无法连接到数据库的错误 这是我的密码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kaç Yakıyor?</title>
<style type="text/css">
body
{
background-color:#CCC;
}
h1.header
{
font-family:"Courier New", Courier, monospace;
font-size:45px;
font-style:oblique;
font-weight:400;
text-align:center;
}
div.content
{
margin-top:100px;
margin-left:auto;
margin-right:auto;
width:61%;
background-color:#F00;
}
div.vehicles
{
margin-top:100px;
width:17%;
height:200px;
background-color:#0F6;
float:left;
}
</style>
</head>
<body>
<?php
mysql_connect("localhost","root","123123") or die(mysql_error());
mysql_select_db("kacyakiyor") or die(mysql_error());
$query = "SELECT marka from arabalar";
$result = mysql_query($query);
if($result){
while($row = mysql_fetch_array($result)){
?>
<h1 class="header">KAÇ YAKIYOR</h1>
<hr width="500px"/>
<div class="vehicles">
<h2><strong><em>Araba</em></strong></h2><hr/><br/>
<?php echo "$row['marka']"; ?>
<h2><strong><em>Motosiklet</em></strong></h2><hr/><br/></div>
<div class="content">asdfasfda
</div>
<?php
}
}
mysql_close();
?>
</body>
</html>
您在使用中出现语法错误
而不是
mysql_fetch_array //and
echo "$row['marka']"
把这个密码
$conn=mysql_connect("localhost","root","123123") or die(mysql_error());
mysql_select_db("kacyakiyor",$conn);
而不是
mysql_connect("localhost","root","123123") or die(mysql_error());
mysql_select_db("kacyakiyor") or die(mysql_error());
尝试更改,看看这是否有帮助/有什么不同。运行此查询,在phpMyadmin中从arabalar中选择marka,然后查看得到的结果..$result=mysql\u query$query$row=mysql\u fetch\u array$result;打印r$行;出口在用HTMLW写之前试试这个你说空白是什么意思?没有输出,即完全没有输出和输出?输出但php部分为空?从容器中删除div.vehicles的样式定义或将class='vehicles'更改为class='vehiclesx'。css可能会隐藏您的内容以防you@Miral事实上,这是我最初/第一次评论中的建议。@DevangRathod By Nope在我对这个问题的第一次评论中,我承认不,它不起作用。@Miral你试过mysql\u query$query或diemsql\u error@Devangarthod没有,但我认为查询没有错,因为我在phpMyAdmin运行此查询时看到了一个结果。@Miral echo hello;inside if$result{然后检查其回显与否inside if condition?从风格上来说,这可能是个好主意,但在这种情况下不会有什么区别。没有任何更改,仍然没有数据。实际上回显$row['marka']应该抛出一个分析错误。这可能取决于PHP版本,但它不会从字符串中的关联数组中展开元素-您必须使用花括号来实现这一点-这将起作用:{$row['marka']}
mysql_fetch_array //and
echo "$row['marka']"
$conn=mysql_connect("localhost","root","123123") or die(mysql_error());
mysql_select_db("kacyakiyor",$conn);
mysql_connect("localhost","root","123123") or die(mysql_error());
mysql_select_db("kacyakiyor") or die(mysql_error());