Scroll to top

How to fetch data by limit in php (How to use sqi in sql in php) (two mysqls)?

 fetch data by limit in php (How to use sqi in sql in php) (two mysqls)

$msg_content = $_POST[‘msg_content’];
$own_id = $_POST[‘own_id’];
$user_id = $_POST[‘user_id’];
global $wpdb;
$table_name13 = $wpdb->prefix . “user_chats”;
$results = $wpdb->get_results(“select  from (select  from $table_name13 where (sender_id =’$own_id’ AND receiver_id=’$user_id’) OR (sender_id =’$user_id’ AND receiver_id=’$own_id’) order by ID DESC LIMIT 10) $table_name13 order by ID”);
$total = count($results);

foreach($results as $result){
$sender_id = $result->sender_id;
$receiver_id = $result->receiver_id;
if($sender_id == $own_id AND $receiver_id == $user_id){
echo “
<div class=’right_side_chat’ style=’text-align:right;background:blue; margin-left:30%; margin-bottom:4px; padding:5px 10px;’>
<span>$result->ID</span>
</div>
“;
}
else{
echo “
<div class=’right_side_chat’ style=’background:red; text-align:left;margin-right:30%;margin-bottom:4px;padding:5px 10px;’>
<span>$result->ID</span>
</div>
“;
}




}

Leave a Reply

Your email address will not be published.