php - How to refresh a database query using jQuery -


i'm working on real basic chat php powered. i'd use jquery check new messages , update #cbox div every few seconds. far have tried accomplishing using code below. frame of reference, first time including jquery of scripts, problem simple error overlooking in newbishness.

the problem i'm running #cbox div displays blank, doesn't seem calling chat_post.php @ all. post code well, in case problem , not jquery. fix, tried including <div id='cbox'> in chat_post.php, yielded no results. @ point, i'm pretty grasping @ straws.

<div id='sb_content'>     <center><div id='chat'>          <div id='ribbon' style='position: relative; margin-top:-50px; margin-left:-32px;'><center><span class='ribbon'>chat box</span></center></div>         <div style='margin-top: -20px;'><center><span style='text-shadow: 0 0 0.2em #000;' class='admin'>admin</span> || <span style='text-shadow: 0 0 0.2em #000;' class='mod'>mod</span></center></div>          <div id="cbox">         <script>         $(document).ready(function() {             setinterval(function(){getupdates()}, 2000);          });          function getupdates() {             $("#cbox").load("chat_post.php");         }         </script>         </div>          <form name="message" method='post' action="chat_post.php" id="cbox_input">             <input name="usermsg"id='usermsg' type="text" size="63" maxlength="255" />         </form>      </div></center>     </div> 

chat_post.php

<div id='cbox' align='left'>  <?php  $username = $_session['login']; $ug = $_session['user_group'];   // display messages $sql = <<<sql select * `chat_entries` order `ts` desc limit 0,50 sql;  $result = $db->query($sql); $count = $result->num_rows;  if ($count != 0){     while ($row = mysqli_fetch_array($result)) {             $c_name = $row['author'];             $c_text = $row['text'];             $c_ts = $row['ts'];             $c_id = $row['id'];  $sqlm = <<<sql select * `users` username = '$c_name' sql;              $resultm = $db->query($sqlm);             $countm = $resultm->num_rows;              if ($count != 0){                 while ($rowm = mysqli_fetch_array($resultm)) {                     $c_level = $rowm['user_group'];                 }             }              if ($c_level == 'mod') {                 echo "                 <a href='/user/" . $c_name . "' class='mod'>" . $c_name . "</a>                 ";             }              if ($c_level == 'admin') {                 echo "                 <a href='/user/" . $c_name . "' class='admin'>" . $c_name . "</a>                 ";             }              if ($c_level == 'member') {                 echo "                 <a href='/user/" . $c_name . "' class='member'>" . $c_name . "</a>                 ";             }              if ($c_level == 'guest') {                 echo "                 <i>" . $c_name . "</i>                 ";             }              echo "             : " . $c_text . "<div id='cbox_div'>";              echo "<span style='float:left;'><i>" . $c_ts . "</i></span>";              echo "<span style='float:right;'>";              if ($ug == 'mod' || $ug == 'admin'){                 echo " <a href='#'>delete</a> || <a href='#'>block</a> ||";             }              if ($_session['login']) {                 echo "<a href=/report/?type=chat?id=" . $c_id . ">report</a></span></div>                 ";             }     } } ?> 

after removing id on chat_post.php, code worked fine. funny how simple can mess things up. (: thank help!


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -