我差不多完成了这个页面。但是,显示此页面时会出现两次而不是一次显示的问题。你看的时候看起来很奇怪。下面有一个截图来查看图像。所以当然,我在显示网页时有错误。我认为PHP代码是我的个人资料。这是代码:
<?php
require('dbconnect.php');//Connects to the database
$id=$_GET['hf_id'];
$query = "SELECT * FROM healingfood WHERE hf_id='$id'";
if(!mysqli_query($link,$query))
{
die("Sorry. There's a problem with the query.");
}
//stores the result of the query
$result = mysqli_query($link,$query);
while($record = mysqli_fetch_assoc($result))
{
$hf_id=$record['hf_id'];
$hf_title=$record['hf_title'];
$a_id=$record['a_id'];
$hf_image=$record['hf_image'];
$hf_description=$record['hf_description'];
$hf_benefits=$record['hf_benefits'];
$hf_source=$record['hf_source'];
$query2 = "SELECT * FROM author";
if(!mysqli_query($link,$query2))
{
die("Sorry. There's a problem with the query.");
}
$result2 = mysqli_query($link,$query2);
while($record2 = mysqli_fetch_assoc($result2)){
$a_id=$record2['a_id'];
$a_lname=$record2['a_lname'];
$a_fname=$record2['a_fname'];
?>
<html>
<head>
<title><?php print $record['hf_title'];?></title>
<link rel="stylesheet" style type="text/css" href="../style.css"><!--External CSS-->
</head>
<body>
<iframe src="../welcome.html" width="100%" height="20%" frameborder="0"><iframe><!--inserts an HTML file using iFrame-->
<br>
<iframe></iframe>
<table border="1" id="1" width="100%"><!--This table cannot be inserted using an iFrame beacuse it will pop in the whole website within a website-->
<tr><!--Creates tabs-->
<th align="center" width="14%"><a href="../homepage.html" title="Home page">Home</a></th>
<th align="center" width="14%"><a href="../recipes.html" title="Recipes">Recipes</a></th>
<th align="center" width="14%"><a href="../healing_food.html" title="Healing Food">Healing Food</a></th>
<th align="center" width="14%"><a href="../videos.html" title="Videos">Videos</a></th>
<th align="center" width="14%"><a href="../contact.html" title="Contact Us">Contact Us</a></th>
<th align="center" width="14%"><a href="../about.html" title="About Us">About Us</a></th>
<th align="center" width="14%"><a href="admin.php" title="Admin">Admin</a></th>
</tr>
</table>
<br>
<div id="three">
<p id="homepagetab" align="center"><?php print $record['hf_title'];?></p>
<p id="normal" align="center"><?php echo "by ".$record2['a_fname']." ".$record2['a_lname'].""?></p>
<img src="<?php print $record['hf_image'];?>" alt="Celery" width="20%" align="right">
<p id="noindent"><b>Description:</b></p>
<p id="normal"><?php print $record['hf_description'];?></p>
<br>
<p id="normal"><b>Benefits:</b> <?php print $record['hf_benefits'];?></p>
<br>
<p id="normal"><b>Source:</b> <a href=" <?php print $record['hf_source'];?> "><?php print $record['hf_source'];?></a></p>
</div>
<br>
<iframe src="../copyright.html" width="100%" height="100%" frameborder="0"></iframe><!--To determine who created this website-->
</body>
<?php } } ?>
</html>
我的错误是什么?
更新:只有作者仍在双重显示。
$id=$_GET['hf_id'];
$query = "SELECT * FROM healingfood WHERE hf_id='$id'";
if(!mysqli_query($link,$query))
{
die("Sorry. There's a problem with the query.");
}
//stores the result of the query
$result = mysqli_query($link,$query);
while($record = mysqli_fetch_assoc($result))
{
$hf_id=$record['hf_id'];
$hf_title=$record['hf_title'];
$hf_image=$record['hf_image'];
$hf_description=$record['hf_description'];
$hf_benefits=$record['hf_benefits'];
$hf_source=$record['hf_source'];
?>
<html>
<head>
<title><?php print $record['hf_title'];?></title>
<link rel="stylesheet" style type="text/css" href="../style.css"><!--External CSS-->
</head>
<body>
<iframe src="../welcome.html" width="100%" height="20%" frameborder="0"><iframe><!--inserts an HTML file using iFrame-->
<br>
<iframe></iframe>
<table border="1" id="1" width="100%"><!--This table cannot be inserted using an iFrame beacuse it will pop in the whole website within a website-->
<tr><!--Creates tabs-->
<th align="center" width="14%"><a href="../homepage.html" title="Home page">Home</a></th>
<th align="center" width="14%"><a href="../recipes.html" title="Recipes">Recipes</a></th>
<th align="center" width="14%"><a href="../healing_food.html" title="Healing Food">Healing Food</a></th>
<th align="center" width="14%"><a href="../videos.html" title="Videos">Videos</a></th>
<th align="center" width="14%"><a href="../contact.html" title="Contact Us">Contact Us</a></th>
<th align="center" width="14%"><a href="../about.html" title="About Us">About Us</a></th>
<th align="center" width="14%"><a href="admin.php" title="Admin">Admin</a></th>
</tr>
</table>
<br>
<div id="three">
<p id="homepagetab" align="center"><?php print $record['hf_title'];?></p>
<?php
$query2 = "SELECT * FROM author";
if(!mysqli_query($link,$query2))
{
die("Sorry. There's a problem with the query.");
}
$result2 = mysqli_query($link,$query2);
while($record2 = mysqli_fetch_assoc($result2)){
$a_lname=$record2['a_lname'];
$a_fname=$record2['a_fname'];
?>
<p id="normal" align="center"><?php echo "by ".$record2['a_fname']." ".$record2['a_lname'].""?></p>
<?php } ?>
<img src="<?php print $record['hf_image'];?>" alt="<?php print $record['hf_title'];?>" width="20%" align="right">
<p id="noindent"><b>Description:</b></p>
<p id="normal"><?php print $record['hf_description'];?></p>
<br>
<p id="normal"><b>Benefits:</b> <?php print $record['hf_benefits'];?></p>
<br>
<p id="normal"><b>Source:</b> <a href=" <?php print $record['hf_source'];?> "><?php print $record['hf_source'];?></a></p>
<?php } ?>
</div>
<br>
<iframe src="../copyright.html" width="100%" height="100%" frameborder="0"></iframe><!--To determine who created this website-->
更新2:我通过在hf_id之后在URL上附加a_id来解决问题。然后,我用$ id2 = $ _ GET ['a_id'];接下来是$ query2 =“SELECT * FROM author WHERE a_id ='$ id2'”; 。而且,它终于奏效了。
答案 0 :(得分:0)
试试这个:
<?php
require('dbconnect.php');//Connects to the database
$id=$_GET['hf_id'];
$query = "SELECT * FROM healingfood WHERE hf_id='$id'";
if(!mysqli_query($link,$query))
{
die("Sorry. There's a problem with the query.");
}
//stores the result of the query
$result = mysqli_query($link,$query);
while($record = mysqli_fetch_assoc($result))
{
$hf_id=$record['hf_id'];
$hf_title=$record['hf_title'];
$a_id=$record['a_id'];
$hf_image=$record['hf_image'];
$hf_description=$record['hf_description'];
$hf_benefits=$record['hf_benefits'];
$hf_source=$record['hf_source'];
$query2 = "SELECT * FROM author";
if(!mysqli_query($link,$query2))
{
die("Sorry. There's a problem with the query.");
}
$hf_benefits = $record['hf_benefits'];
$result2 = mysqli_query($link,$query2);
$hf_title = $record['hf_title'];
$hf_source = $record['hf_source'];
$hf_description = $record['hf_description'];
}
?>
<html>
<head>
<title><?php print $hf_title;?></title>
<link rel="stylesheet" style type="text/css" href="../style.css"><!-- External CSS-->
</head>
<body>
<iframe src="../welcome.html" width="100%" height="20%" frameborder="0"> <iframe><!--inserts an HTML file using iFrame-->
<br>
<iframe></iframe>
<table border="1" id="1" width="100%"><!--This table cannot be inserted using an iFrame beacuse it will pop in the whole website within a website-->
<tr><!--Creates tabs-->
<th align="center" width="14%"><a href="../homepage.html" title="Home page">Home</a></th>
<th align="center" width="14%"><a href="../recipes.html" title="Recipes">Recipes</a></th>
<th align="center" width="14%"><a href="../healing_food.html" title="Healing Food">Healing Food</a></th>
<th align="center" width="14%"><a href="../videos.html" title="Videos">Videos</a></th>
<th align="center" width="14%"><a href="../contact.html" title="Contact Us">Contact Us</a></th>
<th align="center" width="14%"><a href="../about.html" title="About Us">About Us</a></th>
<th align="center" width="14%"><a href="admin.php" title="Admin">Admin</a></th>
</tr>
</table>
<br>
<?php
while($record2 = mysqli_fetch_assoc($result2)){
$a_id=$record2['a_id'];
$a_lname=$record2['a_lname'];
$a_fname=$record2['a_fname'];
?>
<div id="three">
<p id="homepagetab" align="center"><?php print $hf_title;?> </p>
<p id="normal" align="center"><?php echo "by ".$record2['a_fname']." ".$record2['a_lname'].""?></p>
<img src="<?php print $record['hf_image'];?>" alt="Celery" width="20%" align="right">
<p id="noindent"><b>Description:</b></p>
<p id="normal"><?php print $hf_description;?></p>
<br>
<p id="normal"><b>Benefits:</b> <?php print $hf_benefits;?> </p>
<br>
<p id="normal"><b>Source:</b> <a href=" <?php print $hf_source;?> "><?php print $hf_source;?></a></p>
</div>
<br>
<?php } ?>
<iframe src="../copyright.html" width="100%" height="100%" frameborder="0"> </iframe><!--To determine who created this website-->
</body>
</html>