Note that there are some explanatory texts on larger screens.

plurals
  1. POHow To Improve PHP and JQuery Code in this Project - only fade out elements that need refreshed instead of whole section?
    primarykey
    data
    text
    <p>I came across this website and was impressed by it and wanted to try and learn how it works: <a href="http://demo.pellegrom.me/uptime/" rel="nofollow">http://demo.pellegrom.me/uptime/</a></p> <p>My attempt is here: <a href="http://www.4playtheband.co.uk/up/up.php" rel="nofollow">http://www.4playtheband.co.uk/up/up.php</a> but I have had to fade out the entire section rather than just the status'. My tooltips are also broken because they are dynamically generated - I'm sure I need to apply the <code>live</code> function but just not sure on how to do this without breaking it.</p> <p>Here is the code:</p> <p>up.php:</p> <pre><code>&lt;?php require('../db.php'); ?&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("#container").load("response.php").fadeIn("slow"); setInterval(function() { $('#container').fadeOut('slow').load('response.php').fadeIn("slow"); }, 3600000); $('.icon').each(function(){ $(this).simpletip({ showEffect: 'fade', hideEffect: 'fade', fixed: 'true', position: 'right', offset:[10, 0], content: $('img',this).attr('alt') }); }); $('#check').click(function(){ $('.http-status').empty(); $('.http-status').html('&lt;img src="images/spinner.gif"/&gt;'); $('#container').fadeOut('slow').load('response.php').fadeIn("slow"); }); }); &lt;/script&gt; &lt;h2&gt;Website Checker&lt;/h2&gt; &lt;div id="container"&gt;&lt;/div&gt; &lt;br /&gt; &lt;a href="#" id="check" class="button"&gt;Check Now&lt;/a&gt; </code></pre> <p>process.php:</p> <pre><code>&lt;?php require('../db.php'); function Visit($url) { $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";$ch=curl_init(); curl_setopt ($ch, CURLOPT_URL,$url ); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch,CURLOPT_VERBOSE,false); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $page=curl_exec($ch); //echo curl_error($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($httpcode&gt;=200 &amp;&amp; $httpcode&lt;300) { echo '&lt;span class="up"&gt;'.$httpcode.'&lt;span class="icon"&gt;&lt;img src="images/info.png" alt="website is up"/&gt;&lt;/span&gt;&lt;/span&gt;'; } else { $httpcode=404; echo '&lt;span class="down"&gt;'.$httpcode.'&lt;span class="icon"&gt;&lt;img src="images/info.png" alt="website is down"/&gt;&lt;/span&gt;&lt;/span&gt;'; $date = date("l, j \of F Y \@ H:i"); $to = "someone@domain.com"; $subject = "Urgent: $url is down"; $message = "Hello,\n\nIt appears that on our latest check of $url on $date that the site was down.\n\nRegards,\nWeb Checker"; $headers = 'From: noreply@webchecker.co.uk' . "\r\n" . 'Reply-To: noreply@webchecker.co.uk' . "\r\n"; mail($to, $subject, $message, $headers); } } ?&gt; &lt;ul id="site-list" class="list"&gt; &lt;li class="title"&gt; &lt;span class="id"&gt;&lt;/span&gt; &lt;span class="name"&gt;Title&lt;/span&gt; &lt;span class="url"&gt;URL&lt;/span&gt; &lt;span class="status"&gt;HTTP Status&lt;/span&gt; &lt;/li&gt; &lt;?php // some PHP to fetch all the gig entries from the shows table $sql = "SELECT * FROM `check`"; $query = mysql_query($sql) or die(mysql_error()); // a loop to place all the values in the appropriate table cells while ($row = mysql_fetch_array($query)){ //begin the loop... $id=$row['id']; $name=$row['name']; $url=$row['url']; ?&gt; &lt;li&gt; &lt;span class="id"&gt;&lt;?php echo $id; ?&gt;&lt;/span&gt; &lt;span class="name"&gt;&lt;?php echo $name; ?&gt;&lt;/span&gt; &lt;span class="url"&gt;&lt;?php echo $url; ?&gt;&lt;/span&gt; &lt;span class="status http-status"&gt;&lt;?php echo Visit("$url"); ?&gt;&lt;/span&gt; &lt;/li&gt; &lt;?php } ?&gt; &lt;/ul&gt; </code></pre> <p>That's quite a lot of code, apologies if it's difficult to follow.</p> <p>Aside from the two points already mentioned, the only other thing puzzling me is how to avoid the e-mail sending when <code>container</code> is first loaded upon the page being visited?</p> <p>Thanks in advance for all help and suggestions.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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