欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP+Mysql+Ajax實(shí)現(xiàn)淘寶客服或阿里旺旺聊天功能(前臺(tái)頁面)

 更新時(shí)間:2017年06月16日 09:22:09   作者:小魚小魚加油吐泡泡  
這篇文章主要介紹了用php+mysql+ajax實(shí)現(xiàn)淘寶客服或阿里旺旺聊天功能之前臺(tái)頁面,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

首先來看一下我已經(jīng)實(shí)現(xiàn)的效果圖:

消費(fèi)者頁面:(本篇隨筆)

(1)會(huì)顯示店主的頭像

(2)當(dāng)前用戶發(fā)送信息顯示在右側(cè),接受的信息,顯示在左側(cè)

店主或客服頁面:(下一篇隨筆)

(1)在左側(cè)有一個(gè)列表 ,會(huì)顯示所有與店主對話的顧客;該列表可以移動(dòng);有新消息時(shí)會(huì)提示;也可以清空該聊天記錄

(2)點(diǎn)擊列表里的顧客進(jìn)入右邊的對話框界面,顯示與該顧客的聊天信息

 在實(shí)現(xiàn)功能之前,來說一下我用到的兩張表:

 解釋一下:bkid在此處沒有用到;isok列是用來判斷消息是否已讀,未讀為0;

現(xiàn)在,來說一下步驟:(分前臺(tái)和后臺(tái)兩部分)

在這篇隨筆中我們首先來說一下前臺(tái)頁面是如何實(shí)現(xiàn)的:(李四登錄)

用session存取一下lisi;便于后面從user表中取數(shù)據(jù)

1、布局頁面代碼以及讀取數(shù)據(jù)代碼:

<!--中間內(nèi)容-->
 <div id="zhongjian">
  <div id="kuangjia" style="height: 550px;width: 620px; margin: 0px auto;border: 1px solid gainsboro;background-color: white;">
   <div id="neirong" style="height: 400px;width: 600px;">
    <div style="height: 100px;width: 620px;background-image: url(../img/bj4.jpg);">
  //取店主用戶名,顯示店主的頭像和姓名<br>        <?php
   $uid = $_SESSION["uid"];  
   $sql = "select * from users where uid='zhangsan'";
   $arr = $db->query($sql);
   foreach($arr as $v)
   {    
   echo "
   <div style='height:100px;float:left;width:100px;float:left;'>
    <div style='border:2px solid grey;height:84px;width:84px;margin:7px auto; border-radius:10px;overflow:hidden'>
    <img src='{$v[6]}' height='80px' width='80px'/>
    </div>
    </div>
    <div style='height:100px;width:500px;float:left;'>
    <div style='height:50px;width:500px;text-align:left;line-height:50px'>
     親愛的店主
    </div>   
     <div style='height:50px;width:500px;text-align:left;'>個(gè)性簽名:
     <input type='text' placeholder='不讀書怎么對得起今天!' style='width:280px'>        
    </div>
    </div>
    "; 
   }   
   ?>
   </div>
   <div style="height: 300px;width: 620px;overflow: auto;overflow-x:hidden ;"><br>         //獲取session里存取的uid;
    <?php
     $uid = $_SESSION["uid"];     
     $sql3 = "select * from users where uid='{$uid}'";
         $arr3 = $db->query($sql3);<br>                    //從對話表里讀取店主張三和李四所有的對話信息,并按對話時(shí)間順序排序
     $sql2="select * from duihua where uid='{$uid}' or jsid='{$uid}' order by dhtime";     
     $arr2= $db->query($sql2);
     foreach($arr2 as $n)
     {<br>        //如果是店主,則信息要顯示在左側(cè)
     if($n[2]=='zhangsan')
     {
     echo "<div style='height:100px;width:600px;'>
     <div style='height:100px;width:250px;float:left'>
      <div style='height:20px;width:250px;font-size:13px;padding-left:20px'>
        {$n[6]}</div>
      <div style='height:80px;width:50px;float:left'>
       <div style='height:50px;width:50px;margin:0px auto; border-radius:90px;overflow:hidden;'>
        <img src='{$v[6]}' height='50px' width='50px'/>
       </div>
      </div>
      <div style='min-height:40px;width:200px;float:left;background-color:cornflowerblue; border-bottom-right-radius: 10px;border-top-right-radius: 10px;border-top-left-radius: 40px;border-bottom-left-radius: 40px;'>
       <p style='padding-left:20px; line-height:40px'>
        {$n[4]}</p>        
      </div>     
     </div></div>";
     } <br>//如果是李四,則顯示在右側(cè)    
     if($n[2]==$uid)
     {            
     echo "<div style='height:100px;width:600px;margin-right:20px'>
     <div style='height:100px;width:250px; float:right'>
      <div style='height:20px;width:250px;font-size:13px;padding-right:20px'>
        {$n[6]}</div>
      <div style='height:80px;width:50px;float:right'>
       <div style='height:50px;width:50px;margin:0px auto; border-radius:90px;overflow:hidden;'>
        <img src='{$arr3[0][6]}' height='50px' width='50px'/>
       </div>
      </div>
      <div style='min-height:40px;width:200px;float:right;background-color:pink; border-bottom-left-radius: 10px;border-top-left-radius: 10px;border-top-right-radius: 40px;border-bottom-right-radius: 40px;'>
       <p style='padding-left:20px; line-height:40px'>
        {$n[4]}</p>        
      </div>     
     </div></div>"; 
     }          
     }  
     ?>   
   </div>  
   </div> <!--id="neirong"--><br>
  <form role="form">
   <div class="form-group">
   <textarea class="form-control" rows="3" id="words"></textarea> //輸入發(fā)送內(nèi)容
   </div>
  </form>
  <div id="fs" style="height: 50px; width: 600px;text-align: right; padding-right: 50px;">
  <button type="button" class="btn btn-success fasong">發(fā)送</button>  //點(diǎn)擊按鈕發(fā)送
  </div>
  </div>   
  </div> <!--id=zhongjian-->   

實(shí)現(xiàn)效果:

2、點(diǎn)擊發(fā)送時(shí)的ajax代碼:

<script>
 $(".tc").click(function(){
  $("#kuangjia").show();  
 })
  $(".fasong").click(function(){
  var nr=$("#words").val();
  $.ajax({
   url:"qt-speak-cl.php",
   data:{words:nr},
   type:"POST",
   dataType:"TEXT",
   success: function(data){
    if(data==1)
    {
    window.location.href="qt-dh.php" rel="external nofollow" rel="external nofollow" ; 
    }
    else{
     alert("發(fā)送內(nèi)容不能為空!");
    }
    }
  })
 }) 
  $("#dh").click(function(){
  $.ajax({
   url:"qt-yidu-cl.php",
   dataType:"TEXT",
   success: function(data){
//    alert(data);     
    window.location.href="qt-dh.php" rel="external nofollow" rel="external nofollow" ;    
   }   
  })
 })
</script> 

 3、qt-speak-cl.php頁面:

<?php
session_start();
require "DBDA.class.php";
$db = new DBDA(); 
$uid = $_SESSION["uid"];
$words =$_POST["words"];
$chtime=date("Y-m-d H:i:s",time());
$jieshou = "zhangsan";
if(!empty($words))
{
$sql="insert into duihua values ('','{$jieshou}','{$uid}','','{$words}',0,'{$chtime}')";
echo $db->query($sql,0);
<em id="__mceDel">}
else
{ 
 echo "發(fā)送內(nèi)容不能為空!";
}
?>
</em>

 如果發(fā)送內(nèi)容為空,則會(huì)提示“發(fā)送內(nèi)容不能為空!”

前臺(tái)頁面會(huì)隨不同用戶登錄顯示不同的信息;讓王五登錄看看:

以上所述是小編給大家介紹的PHP+Mysql+Ajax實(shí)現(xiàn)淘寶客服或阿里旺旺聊天功能(前臺(tái)頁面),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • PHP isset()與empty()的使用區(qū)別詳解

    PHP isset()與empty()的使用區(qū)別詳解

    本文主要介紹了PHP isset()與empty()的使用區(qū)別。具有很好的參考價(jià)值,下面跟著小編一起來看下吧
    2017-02-02
  • 如何使用OPCache提升PHP的性能

    如何使用OPCache提升PHP的性能

    這篇文章主要介紹了如何使用OPCache提升PHP的性能,幫助大家更好的理解和學(xué)習(xí)使用PHP,感興趣的朋友可以了解下
    2021-04-04
  • 深入淺析PHP無限極分類的案例教程

    深入淺析PHP無限極分類的案例教程

    平時(shí)開發(fā)中或多或少不可避免會(huì)遇到無限極分類的問題,因?yàn)樾?、邏輯等問題也一直使這類問題比較尖銳。今天小編以yii2框架為基礎(chǔ),欄目無限級為例,給大家介紹php無限極分類的相關(guān)知識,感興趣的朋友一起學(xué)習(xí)吧
    2016-05-05
  • 淺談PHP eval()函數(shù)定義和用法

    淺談PHP eval()函數(shù)定義和用法

    下面小編就為大家?guī)硪黄獪\談PHP eval()函數(shù)定義和用法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-06-06
  • laravel如何開啟跨域功能示例詳解

    laravel如何開啟跨域功能示例詳解

    這篇文章主要給大家介紹了關(guān)于laravel如何開啟跨域功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-08-08
  • thinkphp5.0整合phpsocketio完整攻略(繞坑)

    thinkphp5.0整合phpsocketio完整攻略(繞坑)

    這篇文章主要介紹了thinkphp5.0整合phpsocketio完整攻略(繞坑),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-10-10
  • 詳解如何在PHP中使用布隆過濾器

    詳解如何在PHP中使用布隆過濾器

    布隆過濾器(Bloom?Filter)是一種用于快速判斷一個(gè)元素是否屬于某個(gè)集合的概率型數(shù)據(jù)結(jié)構(gòu),本文主要為大家介紹一下如何在PHP中使用布隆過濾器,需要的可以參考一下
    2023-06-06
  • thinkPHP框架實(shí)現(xiàn)的無限回復(fù)評論功能示例

    thinkPHP框架實(shí)現(xiàn)的無限回復(fù)評論功能示例

    這篇文章主要介紹了thinkPHP框架實(shí)現(xiàn)的無限回復(fù)評論功能,結(jié)合實(shí)例形式簡單分析了thinkPHP實(shí)現(xiàn)無限回復(fù)的相關(guān)控制器、視圖操作技巧,需要的朋友可以參考下
    2018-06-06
  • php單鏈表實(shí)現(xiàn)代碼分享

    php單鏈表實(shí)現(xiàn)代碼分享

    這篇文章主要為大家分享了php單鏈表實(shí)現(xiàn)代碼,代碼簡潔,感興趣的小伙伴們可以參考一下
    2016-07-07
  • thinkPHP5框架接口寫法簡單示例

    thinkPHP5框架接口寫法簡單示例

    這篇文章主要介紹了thinkPHP5框架接口寫法,結(jié)合實(shí)例形式分析了thinkPHP5框架數(shù)據(jù)處理接口的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-08-08

最新評論