Skip to main content

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>
";
}




}

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...