Demo entry 6628197

ewfefrefdsfdsdf

   

Submitted by anonymous on Jul 02, 2017 at 03:34
Language: HTML+PHP. Code size: 12.4 kB.

<div class="snippet-container"><div class="sh_default snippet-wrap"><div class="snippet-menu sh_sourceCode"><a class="snippet-window sh_url" href="#">pop-up</a><a class="snippet-text sh_url" href="#">text</a></div><pre class="shi_pre sh_php snippet-formatted sh_sourceCode"><ol class="snippet-num"><li><span class="sh_symbol">&lt;?php</span></li><li><span class="sh_keyword">if</span> <span class="sh_symbol">(</span><span class="sh_keyword">isset</span><span class="sh_symbol">(</span><span class="sh_variable">$_POST</span><span class="sh_symbol">[</span><span class="sh_string">'msg'</span><span class="sh_symbol">]))</span> <span class="sh_cbracket">{</span></li><li>    <span class="sh_variable">$status</span><span class="sh_symbol">=</span><span class="sh_function">time</span><span class="sh_symbol">();</span></li><li>    <span class="sh_variable">$msg</span><span class="sh_symbol">=</span><span class="sh_variable">$_POST</span><span class="sh_symbol">[</span><span class="sh_string">'msg'</span><span class="sh_symbol">];</span></li><li><span class="sh_keyword">if</span> <span class="sh_symbol">(</span><span class="sh_keyword">empty</span><span class="sh_symbol">(</span><span class="sh_variable">$msg</span><span class="sh_symbol">))</span> <span class="sh_cbracket">{</span></li><li>    <span class="sh_keyword">echo</span> <span class="sh_string">"&lt;span&gt;Cannot leave empty&lt;/span&gt;"</span><span class="sh_symbol">;</span></li><li><span class="sh_cbracket">}</span></li><li><span class="sh_keyword">else</span></li><li><span class="sh_cbracket">{</span></li><li>    <span class="sh_variable">$cx_join</span><span class="sh_symbol">=</span><span class="sh_variable">$db</span><span class="sh_symbol">-&gt;</span><span class="sh_function">query</span><span class="sh_symbol">(</span><span class="sh_string">"INSERT INTO cx_chat_msg (uid, msg, ip, dated) VALUES('$uid', '$msg', '$user_ip', '$status')  "</span><span class="sh_symbol">);</span></li><li><span class="sh_cbracket">}</span></li><li></li><li><span class="sh_cbracket">}</span></li><li></li><li><span class="sh_symbol">?&gt;</span>              </li><li></li><li>                <span class="sh_symbol">&lt;</span>div <span class="sh_keyword">class</span><span class="sh_symbol">=</span><span class="sh_string">"panel-body"</span><span class="sh_symbol">&gt;</span></li><li>                    <span class="sh_symbol">&lt;</span>ul <span class="sh_keyword">class</span><span class="sh_symbol">=</span><span class="sh_string">"chat"</span><span class="sh_symbol">&gt;</span></li><li><span class="sh_symbol">&lt;?php</span></li><li></li><li></li><li><span class="sh_variable">$cx_chat_query</span><span class="sh_symbol">=</span><span class="sh_variable">$db</span><span class="sh_symbol">-&gt;</span><span class="sh_function">query</span><span class="sh_symbol">(</span><span class="sh_string">"SELECT * FROM cx_chat_msg M, cx_chat_users U WHERE M.uid=U.uid ORDER BY mid DESC"</span><span class="sh_symbol">);</span></li><li></li><li><span class="sh_variable">$cx_chat</span><span class="sh_symbol">=</span><span class="sh_function">mysqli_num_rows</span><span class="sh_symbol">(</span><span class="sh_variable">$cx_chat_query</span><span class="sh_symbol">);</span></li><li></li><li> <span class="sh_keyword">while</span> <span class="sh_symbol">(</span><span class="sh_variable">$data</span><span class="sh_symbol">=</span><span class="sh_function">mysqli_fetch_assoc</span><span class="sh_symbol">(</span><span class="sh_variable">$cx_chat_query</span><span class="sh_symbol">))</span> <span class="sh_cbracket">{</span></li><li>                 <span class="sh_variable">$msg</span><span class="sh_symbol">=</span><span class="sh_variable">$data</span><span class="sh_symbol">[</span><span class="sh_string">'msg'</span><span class="sh_symbol">];</span></li><li>                 <span class="sh_variable">$muid</span><span class="sh_symbol">=</span><span class="sh_variable">$data</span><span class="sh_symbol">[</span><span class="sh_string">'uid'</span><span class="sh_symbol">];</span></li><li>                 <span class="sh_variable">$mname</span><span class="sh_symbol">=</span><span class="sh_variable">$data</span><span class="sh_symbol">[</span><span class="sh_string">'name'</span><span class="sh_symbol">];</span></li><li>                 <span class="sh_variable">$dated</span><span class="sh_symbol">=</span><span class="sh_variable">$data</span><span class="sh_symbol">[</span><span class="sh_string">'dated'</span><span class="sh_symbol">];</span></li><li></li><li><span class="sh_keyword">if</span> <span class="sh_symbol">(</span><span class="sh_variable">$uid</span><span class="sh_symbol">==</span><span class="sh_variable">$muid</span><span class="sh_symbol">)</span> <span class="sh_cbracket">{</span></li><li>    <span class="sh_comment"># code...</span></li><li>    <span class="sh_keyword">echo</span> <span class="sh_string">'&lt;li class="right clearfix"&gt;&lt;span class="chat-img pull-right"&gt;</span></li><li><span class="sh_string">                            &lt;img src="http://placehold.it/50/FA6F57/fff&amp;amp;text=ME" alt="User Avatar" class="img-circle"&gt;</span></li><li><span class="sh_string">                        &lt;/span&gt;</span></li><li><span class="sh_string">                            &lt;div class="chat-body clearfix"&gt;</span></li><li><span class="sh_string">                                &lt;div class="header"&gt;</span></li><li><span class="sh_string">                                    &lt;small class=" text-muted"&gt;&lt;span class="glyphicon glyphicon-time"&gt;&lt;/span&gt;'</span><span class="sh_symbol">.</span><span class="sh_function">time_passed</span><span class="sh_symbol">(</span><span class="sh_variable">$dated</span><span class="sh_symbol">).</span><span class="sh_string">'&lt;/small&gt;</span></li><li><span class="sh_string">                                    &lt;strong class="pull-right primary-font"&gt;'</span><span class="sh_symbol">.</span><span class="sh_variable">$mname</span><span class="sh_symbol">.</span><span class="sh_string">'&lt;/strong&gt;</span></li><li><span class="sh_string">                                &lt;/div&gt;</span></li><li><span class="sh_string">                                &lt;p&gt;</span></li><li><span class="sh_string">                                    '</span><span class="sh_symbol">.</span><span class="sh_function">convert_clickable_links</span><span class="sh_symbol">(</span><span class="sh_variable">$msg</span><span class="sh_symbol">).</span><span class="sh_string">'</span></li><li><span class="sh_string">                                &lt;/p&gt;</span></li><li><span class="sh_string">                            &lt;/div&gt;</span></li><li><span class="sh_string">                        &lt;/li&gt;'</span><span class="sh_symbol">;</span></li><li><span class="sh_cbracket">}</span></li><li></li><li><span class="sh_keyword">else</span></li><li><span class="sh_cbracket">{</span></li><li><span class="sh_keyword">echo</span> <span class="sh_string">'&lt;li class="left clearfix"&gt;&lt;span class="chat-img pull-left"&gt;</span></li><li><span class="sh_string">                            &lt;img src="http://placehold.it/50/55C1E7/fff&amp;amp;text=U" alt="User Avatar" class="img-circle"&gt;</span></li><li><span class="sh_string">                        &lt;/span&gt;</span></li><li><span class="sh_string">                            &lt;div class="chat-body clearfix"&gt;</span></li><li><span class="sh_string">                                &lt;div class="header"&gt;</span></li><li><span class="sh_string">                                    &lt;strong class="primary-font"&gt;'</span><span class="sh_symbol">.</span><span class="sh_variable">$mname</span><span class="sh_symbol">.</span><span class="sh_string">'&lt;/strong&gt; &lt;small class="pull-right text-muted"&gt;</span></li><li><span class="sh_string">                                        &lt;span class="glyphicon glyphicon-time"&gt;&amp;#8727;&lt;/span&gt;'</span><span class="sh_symbol">.</span><span class="sh_function">time_passed</span><span class="sh_symbol">(</span><span class="sh_variable">$dated</span><span class="sh_symbol">).</span><span class="sh_string">'&lt;/small&gt;</span></li><li><span class="sh_string">                                &lt;/div&gt;</span></li><li><span class="sh_string">                                &lt;p&gt;</span></li><li><span class="sh_string">                                     '</span><span class="sh_symbol">.</span><span class="sh_function">convert_clickable_links</span><span class="sh_symbol">(</span><span class="sh_variable">$msg</span><span class="sh_symbol">).</span><span class="sh_string">'</span></li><li><span class="sh_string">                                &lt;/p&gt;</span></li><li><span class="sh_string">                            &lt;/div&gt;</span></li><li><span class="sh_string">                        &lt;/li&gt;'</span><span class="sh_symbol">;</span></li><li><span class="sh_cbracket">}</span></li><li></li><li></li><li><span class="sh_cbracket">}</span></li><li><span class="sh_symbol">?&gt;</span>    </li><li>                    <span class="sh_symbol">&lt;/</span>ul<span class="sh_symbol">&gt;</span></li><li>                <span class="sh_symbol">&lt;/</span>div<span class="sh_symbol">&gt;</span></li></ol></pre><pre class="snippet-textonly sh_sourceCode" style="display:none;" tabindex="0" contenteditable="">&lt;?php
if (isset($_POST['msg'])) {
    $status=time();
    $msg=$_POST['msg'];
if (empty($msg)) {
    echo "&lt;span&gt;Cannot leave empty&lt;/span&gt;";
}
else
{
    $cx_join=$db-&gt;query("INSERT INTO cx_chat_msg (uid, msg, ip, dated) VALUES('$uid', '$msg', '$user_ip', '$status')  ");
}

}

?&gt;              

                &lt;div class="panel-body"&gt;
                    &lt;ul class="chat"&gt;
&lt;?php


$cx_chat_query=$db-&gt;query("SELECT * FROM cx_chat_msg M, cx_chat_users U WHERE M.uid=U.uid ORDER BY mid DESC");

$cx_chat=mysqli_num_rows($cx_chat_query);

 while ($data=mysqli_fetch_assoc($cx_chat_query)) {
                 $msg=$data['msg'];
                 $muid=$data['uid'];
                 $mname=$data['name'];
                 $dated=$data['dated'];

if ($uid==$muid) {
    # code...
    echo '&lt;li class="right clearfix"&gt;&lt;span class="chat-img pull-right"&gt;
                            &lt;img src="http://placehold.it/50/FA6F57/fff&amp;amp;text=ME" alt="User Avatar" class="img-circle"&gt;
                        &lt;/span&gt;
                            &lt;div class="chat-body clearfix"&gt;
                                &lt;div class="header"&gt;
                                    &lt;small class=" text-muted"&gt;&lt;span class="glyphicon glyphicon-time"&gt;&lt;/span&gt;'.time_passed($dated).'&lt;/small&gt;
                                    &lt;strong class="pull-right primary-font"&gt;'.$mname.'&lt;/strong&gt;
                                &lt;/div&gt;
                                &lt;p&gt;
                                    '.convert_clickable_links($msg).'
                                &lt;/p&gt;
                            &lt;/div&gt;
                        &lt;/li&gt;';
}

else
{
echo '&lt;li class="left clearfix"&gt;&lt;span class="chat-img pull-left"&gt;
                            &lt;img src="http://placehold.it/50/55C1E7/fff&amp;amp;text=U" alt="User Avatar" class="img-circle"&gt;
                        &lt;/span&gt;
                            &lt;div class="chat-body clearfix"&gt;
                                &lt;div class="header"&gt;
                                    &lt;strong class="primary-font"&gt;'.$mname.'&lt;/strong&gt; &lt;small class="pull-right text-muted"&gt;
                                        &lt;span class="glyphicon glyphicon-time"&gt;&amp;#8727;&lt;/span&gt;'.time_passed($dated).'&lt;/small&gt;
                                &lt;/div&gt;
                                &lt;p&gt;
                                     '.convert_clickable_links($msg).'
                                &lt;/p&gt;
                            &lt;/div&gt;
                        &lt;/li&gt;';
}


}
?&gt;    
                    &lt;/ul&gt;
                &lt;/div&gt;</pre></div></div>

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).