这里的逻辑错误是页脚边距位置受到while循环结果的影响。
以下是问题的逻辑视图:https://www.dropbox.com/s/oxyt5o4pzmarome/before%20and%20after.png?dl=0
这是我的代码:
<div id="print_output1">
<?php
$con=mysql_connect("localhost","root","");
mysql_set_charset("UTF8", $con);
if(!$con)
{
die("Could not connect." .mysql_error());
}
mysql_select_db("dictionary_enhanced", $con);
if (isset($_POST['word']))
{
$search = $_POST['word'];
$search1=addslashes($search);
$query = "SELECT *" .
" FROM maranao, maranao_meaning, english, filipino, translate".
" WHERE maranao.mar_id = maranao_meaning.mar_id and maranao.mar_id = translate.mar_id and filipino.fil_id = translate.fil_id and english.eng_id = translate.eng_id and maranao.maranao_word like '$search1%' ORDER BY maranao.maranao_word ASC";
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if($num_rows==0)
{
echo "No Results Found. Please try again";
}
$previous_word = "";
$row = 0;
while($row = mysql_fetch_array($result))
{
// AM - Show the word only if it's a new one
if ($row["maranao_word"] != $previous_word)
{
echo "<div style='margin-bottom: 3px; color: white;'>.</div>";
// AM - close the previous word definition
if ($row == 0)
{
}
?>
<div style = "font-family:'Times New Roman'; font-size: 17px;">
Maranao word: <b><i><?php echo $row['maranao_word']; ?></i></b><br>
English word: <b><?php echo $row['english_word']; ?></b><br>
Filipino word: <b><?php echo $row['filipino_word']; ?></b><br>
Definition:
<?php
}
?>
<font color="white">:</font>
<div style="width:600px; border:0px solid orange; margin-left: 100px; word-wrap:break-word; margin-top: -17px;"><b><ul><li><?php echo $row['definition'] ?></li></ul></b></div>
<?php
// AM - Update the previous word and the row count
$previous_word = $row["maranao_word"];
$row++;
//echo "<br>";
}
// AM - close the last word definition
if ($row > 0)
{ echo "</div><br>"; }
}
mysql_close($con);
?>
</div><!-----end id="print_output1" ------>
</div><!-----end of id="container" ------>
</div><!-------end border shadow------->
<div id="footer"> <!---footer------>
footer <!---the footer here is affected when displaying all the results from the while loop above--->
</div>
</div> <!---------id="wrap"---->
答案 0 :(得分:0)
你还没有关闭while循环中的div。尝试使用以下代码
<div id="print_output1">
<?php
$con = mysql_connect("localhost", "root", "");
mysql_set_charset("UTF8", $con);
if (!$con) {
die("Could not connect." . mysql_error());
}
mysql_select_db("dictionary_enhanced", $con);
if (isset($_POST['word'])) {
$search = $_POST['word'];
$search1 = addslashes($search);
$query = "SELECT *" .
" FROM maranao, maranao_meaning, english, filipino, translate" .
" WHERE maranao.mar_id = maranao_meaning.mar_id and maranao.mar_id = translate.mar_id and filipino.fil_id = translate.fil_id and english.eng_id = translate.eng_id and maranao.maranao_word like '$search1%' ORDER BY maranao.maranao_word ASC";
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows == 0) {
echo "No Results Found. Please try again";
}
$previous_word = "";
$row = 0;
while ($row = mysql_fetch_array($result)) {
// AM - Show the word only if it's a new one
if ($row["maranao_word"] != $previous_word) {
echo "<div style='margin-bottom: 3px; color: white;'>.</div>";
// AM - close the previous word definition
if ($row == 0) {
}
?>
<div style = "font-family:'Times New Roman'; font-size: 17px;">
Maranao word: <b><i><?php echo $row['maranao_word']; ?></i></b><br>
English word: <b><?php echo $row['english_word']; ?></b><br>
Filipino word: <b><?php echo $row['filipino_word']; ?></b><br>
Definition:
<?php
}
?>
<font color="white">:</font>
<div style="width:600px; border:0px solid orange; margin-left: 100px; word-wrap:break-word; margin-top: -17px;"><b><ul><li><?php echo $row['definition'] ?></li></ul></b></div>
<?php
// AM - Update the previous word and the row count
$previous_word = $row["maranao_word"];
$row++;
echo "</div>";
//echo "<br>";
}
// AM - close the last word definition
if ($row > 0) {
echo "</div><br>";
}
}
mysql_close($con);
?>
</div><!-----end id="print_output1" ------>
页脚