I have got this HTML
<div class="V_CPp">
<span class="ViewC">View more comments</span>
</div>
<div class="hov_c">
<div class="CommentsAwp Comment_Hs CA">
<img src="../users/<?php echo $CommenterPicture[0];?>">
<span><?php echo $CommenterName[0]; ?></span>
<span class="s2"><?php echo $CommentRow[1]; ?></span>
</div>
</div>
And this Jquery/AJAX
$(".V_CPp").click(function(event) {
var numItems = $(this).siblings('.F_W_comments').children().children().length;
var i=$(this).siblings(".c_jq").children(".Likes").attr("data-i");
$.ajax({
url: '../connect.php',
type: 'GET',
cache: false,
contentType: false,
processData: false,
data:"VMC="+i+"&NI="+numItems,
success: function(data)
{
$("body").html(data);
}
});
});
And this php(connect.php)
if (isset($_GET['VMC'])) {
$RandS=$_GET['VMC'];
$From=$_GET['NI'];
$To=$From+4;
$query=$con->query("SELECT id FROM uploads WHERE Rand='$RandS'");
$Id=$query->fetch_row();
$Commentsq=$con->query("SELECT * FROM (SELECT * FROM comments WHERE Post_id='$Id[0]' ORDER BY `DATE` DESC LIMIT $From,$To) AS sub ORDER BY `DATE` ASC");
while($COMM=$Commentsq->fetch_row())
{
echo $COMM[1]."<br />";
}
}
So when i have lets say 13 comments in order from 1 to 13
It only shows 10-13 and when i click
<div class="V_CPp">
It shows me all comments from 2 to 9 instead of 6-9
Did you try with
<span class="s2"><?php echo $CommentRow[0]; ?></span>
instead
<span class="s2"><?php echo $CommentRow[1]; ?></span>
Try and comment please, maybe this is the issue.
Best of lucks,
Related
I'm currently using JQuery UI Dragabble, Droppable and sortable. I have two div sections at top and bottom of my php file were i'm dragging and dropping contents from bottom to top div sections.
In top div section i'm performing Sortable JQUery opertions my next requirment is when i perform sorting operation in top section its order should be automatically updated in my MYSQL DB i gotta stuck like how to pass the sorted order to my MySQL db via ajax and php file. Can somebody suggest some help in Achieving it!
Thanks!
Html/PHP code
<div class="drop_list">
<ol id="sortable" style="list-style:decimal;"></ol>
</div>
<div class="sort_list">
<ul id="draggable">
<?php
for($i=1;$i<=5;$i++)
{
?>
<li data-id='article_<?php echo $i;?>' class="draggable_li qitem" >
<div class="main_div">
<div class="secondary_div">
<div class="form_div">
<form>
<input style="width:15px;" type="checkbox" class="hello"/>
</form>
</div>
<label class="item_div">
<span class="item">Item = <?php echo $i; ?></span>
</label>
</div>
<button class="hello btn btn-success add_top">
Add to Top Stories
</button>
<span class="AH_section" style="display:none;float:right;">
<input type="checkbox"/>Home Section
<input type="checkbox"/>App Home Section
</span>
</div>
</li>
<?php
}
?>
</ul>
</div>
</div>
</div>
</div>
JQuery code
$(document).ready(function() {
$("#sortable").sortable({
revert: true,
refreshPositions: true ,
helper : 'clone',
cursor: "move",
delay: 1,
tolerance: 'pointer',
revert: 50
/*stop:function(event,ui){
var data = $(this).sortable('serialize');
}*/
}).serialize();
$("ol li").disableSelection();
$(".sort_list li").draggable({
//containment : "#container",
tolerance:"pointer",
helper : 'clone',
refreshPositions: true ,
revert : 'invalid',
opacity:.4,
});
$(".drop_list ol").droppable({
revert:true,
//hoverClass : 'ui-state-highlight',
greedy: true,
refreshPositions: true,
drop : function(ev, ui)
{
$(ui.draggable).clone().appendTo(this);
if($(this)[0].id === "sortable")
{
console.log($(this).closest("button").find('.hello'));
$(this).find('.hello').hide();
$(this).find('.AH_section').show();
//$(ui.draggable).draggable( 'disable' ); //this will not append dragged list at top of the container
ui.draggable.draggable( 'disable' ).closest('li').prependTo(ui.draggable.closest('ul')); //this will append dragged list at top of the container
return true;
}
}
});
});
change data-id='article_<?php echo $i;?>' to id='<?php echo $i;?>'
add this to your sortable(),
update: function (event, ui) {
var serial=$(this).sortable('serialize');
save_sortable(serial);
}
so here on update, you are calling save_sortable() function, from ajax , update your db in the order returned from sortable()
function save_sortable(serial)
{
$.ajax({
url: "path to your file to update in db.",
type: 'POST',
data: serial,
success: function (data) {
//alert(data);
}
});
}
You can add some id attribute to li, in my case will be get_id.
and then call below function onDropSendSort(); when you want, ie after drop.
<li data-id='article_<?php echo $i;?>' get_id="<?php echo $object_id; ?>" class="draggable_li qitem" >
function onDropSendSort() {
var data = [];
$('#draggable li').each(function() {
var id = $(this).attr('get_id');
data.push(id);
});
// data = [id_1, id_3, id_n];
$.ajax({
url: 'some_url',
type: 'POST',
data: {sort: data},
complete: function(res) {
console.info(res);
}
});
}
In my website there are many categories. Each category page have their posts. Here I used jQuery datepicker, if user want to see Aug 20th posts, they click particular date on calender & see the date posts. One more thing, if I open one category the posts of today should be displayed only. Please check this code and help me. This code displays all posts of category & datepicker is not retrieving anything.
This is mysql query in function.php
if(isset($_REQUEST['datepost']))
{
$date = $_POST['date'];
$res=mysql_query("SELECT * FROM `wp_posts` WHERE DATE_FORMAT(post_date, '%m/%d/%Y' ) = '%m/%d/%Y' AND post_type = 'post' ORDER BY post_date DESC");
$pageposts=mysql_fetch_array($res);
exit();
}
?>
This is my script & PHP code:
<script type="text/javascript">
$(function() {
<!--current date posts-->
var currentTime = new Date();
var day = currentTime.getDate();
var month = currentTime.getMonth() + 1;
var year = currentTime.getFullYear();
if (day < 10) {
day = "0" + day;
}
if (month < 10) {
month = "0" + month;
}
var today_date = day + "/" + month + "/" + year;
var dataString ='date='+today_date;
$.ajax ({
type: "POST",
url: "<?php echo home_url(); ?>/?datepost",
data: dataString,
success: function(data) {
$('#testdiv').html(data);
}
}); <!--End current date posts-->
<!--select date posts-->
$("#datepicker").datepicker ({
onSelect: function(dateTypeVar, inst) {
var dateAsObject = $(this).val();
var dataString ='date='+dateAsObject;
$.ajax ({
type: "POST",
url: "<?php echo home_url(); ?>/?datepost",
data: dataString,
success: function(data) {
$('#testdiv').html(data);
}
}); <!--End select date posts-->
}
});
});
</script>
PHP coding:
Date: <input type="text" id="datepicker" size="30"/>
<?php while (have_posts()) :the_post();
?>
<div id="testdiv">
<div class="featuredpost">
<div class="cat-block">
<?php the_post_thumbnail( 'homepage-catpage' ) ?>
<h2 class="posttitle"> <a href="<?php echo the_permalink();?>" rel="bookmark" title="" ><?php echo $key_1_values = get_post_meta($postid, '_visual-subtitle', true ); ?></a>
</h2>
<p> <?php $content = get_the_excerpt();
$contentrecord=htmlspecialchars_decode(strip_tags(stripslashes($content)));
echo substr($contentrecord, 0, 350); ?></p>
<p class="postmeta"><span class="meta_date"><?php the_time('Y/m/d g:i:s A'); ?>
<input id="name" type="hidden" value="<?php echo $postid; ?>" name="post__id">
<p>
</span><span class="meta_permalink">التفاصيل </span> </p>
</div>
</div>
</div>
<?php endwhile;
wp_reset_query();?>
</div>
<?php if(isset($_REQUEST['datepost']))
{
$date = date('m/d/Y',strtotime($_POST['date']));
$res=mysql_query("SELECT * FROM `wp_posts` WHERE DATE_FORMAT(post_date, '%m/%d/%Y' ) = $date AND post_type = 'post' ORDER BY post_date DESC");
$pageposts=mysql_fetch_array($res);
exit();
}
?>
Provide actual value for post_date column like DATE_FORMAT(post_date, '%m/%d/%Y' ) = $date
I have to get the value of something when I press an accordion div. This div=" accordion" has this structure:
<div class="accordion">
<? if ($_SESSION[SITE]['user']['id'] == $message['yp_from']) { ?> <div class="row"><span class="bold">From: </span> <span>Me</span>
<span class="grey9"> <?= $this->tools_lib->date_format($message['yp_time']); ?></span>
<? } else { if ($message['yp_state_from'] == 0) {?>
<div class="row"><span class="bold">From: </span><span><?= $this->tools_lib->name_separate($message['yp_name']) ?></span>
<div id="idMens<?= $message['id'] ?>" style="display:none;" class="showNew"><?= $message['id'] ?></div></span>
<h5 id="new"> New </h5>
<?} else { ?>
<div class="row"><span class="bold">From: </span><span><?= $this->tools_lib->name_separate($mensaje['yp_name']) ?></span>
<? }
} ?>
</div>
<p><?= $message['yp_message'] ?><p>
</div>
I want to get · $mensaje['id'] · value from the "div id="idMens"". I was trying to do it with jquery. but I have problems to get the correct value, it always take the first item value, I mean the last dinamically typed.
Im trying to use this jquery code. but I think is not well formed code..
<script>
$(document).ready(function(){
$('.accordion').find('div').click(function(){
$(this).next().slideToggle();
$('.showNew').on('click', function() {
var idm =this.id;
});
var form_data = {
to: $('#',idm).html()
}
$.ajax({
url: _baseurl+""+_lang+"/messages/updateState/", // ruta del controlador y accion
type: 'POST',
data: form_data,
success: function(data){
$('#new').hide();
}
});
}).next().hide();
});
</script>
Thank you!
Finally I did it. I'm fool... it was so easy. I was in the wrong way.
I did it creating other function:
function changeState(id){
var form_data = {
to: id
}
$.ajax({
url: _baseurl+""+_lang+"/messages/updateState/", // ruta del controlador y accion
type: 'POST',
data: form_data,
success: function(data){
$('#new').hide();
}
});
}
And calling it in the first div. with onclick. I pass the dinamic id as a parameter and therefore I can use it well.
Thank you
I have a table that queries from a database that is updated frequently, and where
<span id="totalvotes1"></span>
and where
<span id="totalvotes2"></span>
I need to be able to be able to identify those in the line
success: function(data) { $('#totalvotes1').text(data); } });
in my ajax for each corresponding row queried... the way it is set up right now, my ajax will just display the information back into
<span id="totalvotes1"></span>
in the last row queried....
<?php
$sql = mysql_query("SELECT * FROM blogData ORDER BY id DESC");
$sql2=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 0 ORDER BY mes_id DESC");
$sql3=mysql_query("SELECT * FROM messages WHERE mod(mes_id,2) = 1 ORDER BY mes_id DESC");
$count_variable = 0;
while(($row = mysql_fetch_array($sql))AND($row2 = mysql_fetch_array($sql2))AND($row3 = mysql_fetch_array($sql3)) ){
$id = $row['id'];
$title = $row['title'];
$content = $row['content'];
$category = $row['category'];
$podcast = $row['podcast'];
$datetime = $row['datetime'];
$message1=$row2['msg'];
$mes_id1=$row2['mes_id'];
$totalvotes1=$row2['totalvotes'];
$message2=$row3['msg'];
$mes_id2=$row3['mes_id'];
$totalvotes2=$row3['totalvotes'];
?>
<table class="content">
<tr>
<td>
<div id="main">
<div id="left">
<span class='up'><img src="up.png" alt="Down" /></span><br />
<span id="totalvotes1"><?php echo $totalvotes1; ?></span><br />
</div>
<div id="message">
<?php echo $message1; ?>
</div>
<div class="clearfix"></div>
</div>
<div id="main">
<div id="right">
<br />
<span id="totalvotes2"><?php echo $totalvotes2; ?></span><br />
<span class='down'><img src="down.png" alt="Down" /></span>
</div>
<div id="message">
<?php echo $message2; ?>
</div>
<div class="clearfix"></div>
</div>
</td>
</tr>
</table>
<?php
}
?>
here is my general.js file
$(".vote").click(function()
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var eData = $(this).attr("data-options");
var dataString = 'id='+ id + '&' + eData ;
var parent = $(this);
if(name=='up')
{
$(this).fadeIn(200).html('');
$.ajax({
type: "POST",
url: "up.php",
data: dataString,
cache: false,
success: function(data) { $('#totalvotes1').text(data); }
});
}
else
{
$(this).fadeIn(200).html('');
$.ajax({
type: "POST",
url: "down.php",
data: dataString,
cache: false,
success: function(data) { $('#totalvotes2').text(data); }
});
}
});
});
});
Possibly a earlier version of your latest question,
JSON encode, ajax and display back in html
In my answer on your latest question about this, I've given a detailed example of how to use JSON data between PHP and jQuery.
hello friends i am making a live search with the help of ajax and mysql. the problem is that when we write something suppose a alphabet "a" then it gives live results but when i put a space and then write any alphabet suppose "a" then results does no shows up . how can we ignore the spaces in the search ?? my code is
ajax search.php
<script type="text/javascript">
$(document).ready(function(){
$(".search").keyup(function()
{
var searchbox = $(this).val();
var dataString = 'searchword='+ $.trim(searchbox);
if(searchbox=='')
{
$('#display123').hide();
}
else
{
$.ajax({
type: "POST",
url: "friends/search1.php",
data: dataString,
cache: false,
success: function(html)
{
$("#display123").html(html).show();
}
});
}return false;
});
});
</script>
mysql search1.php
<?php include($_SERVER["DOCUMENT_ROOT"]."/sexy/include/connection.php");
if($_POST)
{
$q=$_POST['searchword'];
$sql_res=mysql_query("select * from users_profile where fname like '%$q%' or Email like '%$q%' order by rand() LIMIT 10");
while($row=mysql_fetch_array($sql_res))
{
$fname=$row['fname'];
$lname=$row['lname'];
$img=$row['profile_pic'];
$country=$row['country'];
$uid=$row['uid'];
$re_fname='<b>'.$q.'</b>';
$re_lname='<b>'.$q.'</b>';
$final_fname = str_ireplace($q, $re_fname, $fname);
$final_lname = str_ireplace($q, $re_lname, $lname);
?>
<div class="display_box" >
<span><img src="<?php echo $img; ?>" width="50" height="50" style="float:left; margin-right:6px" /></span>
<div class="searchtext"><a href="profile.php?f_id=<?php echo $uid;?>"><?php echo $final_fname; ?> <br/>
<span style="font-size:10px; color:#999999"><?php echo $country; ?></span></a></div></div>
<?php
}
}
else
{
}
?>
You can trim whitespaces before using the variable in query, like:
$q= trim($_POST['searchword']); //remove whitespaces from front and end