所以,我有这个php文件,但是第一个结果没有包含在'result'div中,因此没有正确设置样式。所有后续结果都被正确包装。帮助
编辑: 根据评论,我试图将html拉出来。我承认我是一个菜鸟,但这就是我为此而想出的。似乎没有解决原始问题:
scripts_post.php:
$connection = mysqli_connect("server", "user", "password", "dbname");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($connection, $sqlQuery);
mysqli_close($connection);
if (empty($result)) {
echo 'No results found';
return;
}
while($row = mysqli_fetch_array($result))
{
echo include 'single_result.php';
}
echo "<div class='results_end'><p>End of list</p></div>";
single_result.php:
<div class='result'>
<div class='result_left'>
<div class='result_photo'><img src=<?php echo "'" . $row['PhotoLink'] . "'" ?> height='200' width='200' class='script_photo'></div>
</div>
<div class='results_right'>
<div class='result_title'><?php echo $row['Title'] ?></div>
<div class='result_summary'><?php echo $row['Summary'] ?></div>
<div class='result_description'><?php echo $row['Description'] ?></div>
<div class='result_preview'><a href =<?php echo "'" . $row['PreviewLink'] . "'" ?> target='_blank'>view preview</a></div>
<div class='result_detail'>Type: <?php echo $row['Type'] ?></div>
<div class='result_detail'>Biblical Characters Portrayed: <?php echo $row['BiblicalCharacters'] ?></div>
<div class='result_detail'>Topics: <?php echo $row['Topics'] ?></div>
<div class='result_price'>Cost: $<?php echo $row['Price'] ?></div>
<div class='result_purchase'><a href =<?php echo "'" . $row['DownloadLink'] . "'" ?> target='_blank'><img src='http://image.payloadz.com/images/btn-addtocart-b.png' border='0'></a></div>
</div>
</div>
编辑#2:这就是上面所说的。也许这里有些东西搞砸了?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js">
</script>
<script language ="javascript">
$(function() {
$('form').submit(function(event) {
var form = $(this);
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: form.serialize()
}).done(function(returned_data) {
document.getElementById('scriptsearch_results_div').innerHTML = returned_data;
}).fail(function() {
alert("The search has failed. Please alert the webmaster.");
});
event.preventDefault();
});
});
</script>
...
<div id="formcontainer">
<form id="scriptsearch_form" action="scripts_post.php" method="post">
// form fields
<p> <input type="submit" value="Search" class="submitbutton" id="mainsubmitbutton"> </p>
</form>
</div>
<div id="scriptsearch_results_div">
<p>Search for scripts using the options at left.</p>
</div>
答案 0 :(得分:0)
你需要取出结果&#39;来自php循环的div。换句话说,将php循环嵌套在&#39;结果&#39; div
中答案 1 :(得分:0)
发现了这个问题。傻,真的。 scripts_post.php中的<body>
标记实际上是<body
,因此第一个>
正在关闭标记,其间的内容被转储。
答案 2 :(得分:-1)
您应该转换来自数据库的文本中的特殊字符,因为它们可能会破坏您的HTML(我猜这是第一个div中发生的事情)
所以,而不是:
<div class='result_summary'><?php echo $row['Summary'] ?></div>
它应该是:
<div class='result_summary'><?php echo htmlspecialchars($row['Summary']) ?></div>
执行的翻译是:
&
"
。'
(或')。<
>