【发布时间】:2015-11-15 19:57:50
【问题描述】:
我有一个博客并从一些 SQL 数据库中获取数据。 我在从 foreach 循环中获取正确数据时遇到问题,我不知道为什么。我会尽力解释。
对于每张图片,都有一个文本区域,用户可以在其中发表评论。对于每条评论,我必须发送相应的 id (ajax) 以添加到数据库中。
foreach($db->query("SELECT id, image FROM news") as $row)
{
<a href='images/news/{$row['image']}'><img src='images/news/{$row['image']}'/></a>";
<div class="save_comment">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>
<input type="text" class="_comment_id" name="id" value="<?php print_r($row['id'] );?>" />
Comment:
<textarea id="_comment_text" class="comment_area" name="comment_area" maxlength="400" cols="80" rows="8" ></textarea>
</td>
</tr>
<tr>
<td>
<a class="post_comment" href=".popupContainer">Post Comment</a>
</td>
</tr>
</table>
</div>
}
点击“发表评论”后,js-script 将被初始化....
<script type="text/javascript">
jQuery(document).ready(function() {
$(".post_comment").leanModal({top : 200, overlay : 0.6, closeButton: ".modal_close" });
$(function(){
jQuery('.tabs .tab-links a').on('click', function(e) {
var currentAttrValue = jQuery(this).attr('href');
jQuery('.tabs ' + currentAttrValue).show().siblings().hide();
jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
e.preventDefault();
});
});
});
</script>
....并显示一个弹出容器(类 .popupContainer 的 div),用户最终可以在其中提交评论。
<div class="popupContainer" style="display:none;">
Your Name: <input type="text" class="_user_name" />
Email:<input type="text" class="_comment_email" />
<input type='button' class='_submit_comment' value='Speichern' >
</div>
通过提交此评论,以下脚本被初始化,数据将通过 ajax 发送。
<script type="text/javascript">
$("._submit_comment").click(function(){
var parentObj = $(this).closest('.save_comment');
var _comment_id = parentObj.find('._comment_id').val(); -> I don't get the correct id
所以问题就从这里开始了。我只从 foreach 循环中获取第一个 id,但我需要为每条评论获取相应的 id。任何人都可以帮助解决这个问题吗? 谢谢 混蛋
【问题讨论】:
-
谁能帮我解决这个问题,或者告诉我哪里出了问题(逻辑)?