首次迭代的sql查询未正确包装 [英] first iteration of sql query not being wrapped properly
问题描述
所以,我有这个php文件,但第一个结果没有被包装在'结果'div,所以没有正确的样式。所有后续结果被正确包装。帮助?
编辑:
根据评论,我试图拉出html。我承认我是一个noob,但这里是我提出了这一点。似乎无法解决原始问题:
scripts_post.php:
p $ p> $ connection = mysqli_connect(server,user,password,dbname);
if(mysqli_connect_errno())
{
echo无法连接到MySQL:。 mysqli_connect_error();
}
$ result = mysqli_query($ connection,$ sqlQuery);
mysqli_close($ connection);
if(empty($ result)){
echo'未找到结果';
return;
}
while($ row = mysqli_fetch_array($ result))
{
echo include'single_result.php';
}
echo< div class ='results_end'>< p>列表结尾< / 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'>查看预览< / 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'>主题:<?php echo $ row ['Topics']?>< / div>
< div class ='result_price'>费用:$<?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 b $ b type:form.attr('method'),
url:form.attr('action'),
data:form.serialize()
})done (returned_data){
document.getElementById('scriptsearch_results_div')。innerHTML = returned_data;
})。fail(function(){
alert(搜索失败,请提醒网站管理员。);
});
event.preventDefault();
});
});
< / script>
...
< div id =formcontainer>
< form id =scriptsearch_formaction =scripts_post.phpmethod =post>
//表单字段
< p> < input type =submitvalue =Searchclass =submitbuttonid =mainsubmitbutton> < / p>
< / form>
< / div>
< div id =scriptsearch_results_div>
< p>使用左侧的选项搜索脚本。< / p>
< / div>
找到问题。傻,真的。 scripts_post.php中的< body>
标记实际上是< body
,因此第一个>
正在关闭标签,其中的内容被转储。
So, I've got this php file, but the first result isn't being wrapped in the 'result' div, and so isn't being styled properly. All the subsequent results are being wrapped properly. Help?
EDIT: Per the comments, I've tried to pull the html out. I admit I'm a noob, but here's what I've come up with for that. Doesn't seem to fix the original issue:
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>
EDIT #2: Here's what's calling the above. Perhaps there's something here that's screwing with things?
<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>
Found the issue. Silly, really. the <body>
tag in scripts_post.php was actually <body
and so the first >
was closing the tag and the stuff between was being dumped.
这篇关于首次迭代的sql查询未正确包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!