Note that there are some explanatory texts on larger screens.

plurals
  1. POImproving polling with ajax and php
    text
    copied!<p>This is working, however I think it maybe resorce hungry, is there any way to improve it?</p> <p>Adds callback to db(test.php):</p> <pre><code>extract($_REQUEST); $query = "INSERT INTO calls ( `timestamp`, `fromnum`, `tonum` ) VALUES ( NOW(), '".mysql_real_escape_string( $from )."', '".mysql_real_escape_string( $to )."' )"; $sql = mysql_query($query) or die(mysql_error()); </code></pre> <p>Gets the last entry in the calls table (queue.php):</p> <pre><code>$result = mysql_query("SELECT fromnum FROM calls WHERE tonum = '$tonum' ORDER BY timestamp DESC LIMIT 1"); while($row = mysql_fetch_array($result)) { $fromnum = $row['fromnum']; } // Get caller info from contacts db $result = mysql_query("SELECT * FROM contacts WHERE phone = '$fromnum'"); while($row = mysql_fetch_array($result)) { echo '&lt;table width="100%" border="0"&gt; &lt;tr&gt; &lt;td width="33%"&gt;Account Number&lt;/td&gt; &lt;td width="33%"&gt;Contact Name&lt;/td&gt; &lt;td width="33%"&gt;Phone Number&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;'.$row['number'].'&lt;/td&gt; &lt;td&gt;'.$row['name'].'&lt;/td&gt; &lt;td&gt;'.$row['phone'].'&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;'; } </code></pre> <p>Call the info from queue.php(listen.php):</p> <pre><code>var auto_refresh = setInterval( function () { $('#response').load('queue.php').fadeIn("slow"); }, 1000); // refresh every 10000 milliseconds &lt;/script&gt; &lt;div id="response"&gt;&lt;/div&gt; </code></pre> <p>Thanks for looking, any help welcome!</p> <p>Cheers, B.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload