Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

http://furious-angel.com

« Newer Snippets
Older Snippets »
Showing 1-7 of 7 total  RSS 

Call Total Number From MySQL Row

// Call total count from MySQL row

   1  
   2  <?
   3  // Query the database and get the count
   4  $result = mysql_query("SELECT * FROM TABLE_NAME");
   5  $num_rows = mysql_num_rows($result);
   6  
   7  // Display the results
   8  echo $num_rows;
   9  ?>

Connect to MySQL

// Connect to MySQL Database

   1  
   2  //connect to your database ** EDIT REQUIRED HERE **
   3  mysql_connect("localhost","username","password"); //(host, username, password)
   4  
   5  //specify database ** EDIT REQUIRED HERE **
   6  mysql_select_db("database") or die("Unable to select database"); //select which database we're using

Local Time & Date

// description of your code here

   1  
   2  <?php
   3  $timezone = "the UK";
   4  $time_diff = "0";
   5  $alter = ($time_diff * 60 * 60);
   6  $date_today = date ("l F jS Y", time () + $alter);
   7  $time_now = date ("h:ia", time () + $alter);
   8  
   9  echo "It's currently <strong>$time_now</strong> on <strong>$date_today</strong> in <strong>$timezone</strong>.";
  10  ?>

Back to Top

// description of your code here

   1  
   2  <a href="#" onclick="window.scrollTo(0,0); return false">Back to Top</a>

Forward, Top & Back

// Link forward, top and back on your pages

   1  
   2  <a href="javascript:history.back();">Back A Page</a> | <a href="#" onclick="window.scrollTo(0,0); return false">Back to Top</a> | <a href="javascript:history.forward();">Forward A Page</a>

Javascript Image PreLoad

// Javascript Image Preload
   1  
   2  <script type="text/javascript">
   3      <!--
   4  
   5      if (document.images)
   6      {
   7        preload_image_object = new Image();
   8        // set image url
   9        image_url = new Array();
  10        image_url[0] = "http://mydomain.com/image0.gif";
  11        image_url[1] = "http://mydomain.com/image1.gif";
  12        image_url[2] = "http://mydomain.com/image2.gif";
  13        image_url[3] = "http://mydomain.com/image3.gif";
  14  
  15         var i = 0;
  16         for(i=0; i<=3; i++) 
  17           preload_image_object.src = image_url[i];
  18      }
  19  
  20      //-->
  21      </script> 

Page Last Modified

// PHP snippet to output the date a file was last updated

   1  
   2  <?
   3  $last_modified = filemtime("pagename.php");
   4  print("Last Modified");
   5  print(date("j/m/y h:i", $last_modified));
   6  ?>
« Newer Snippets
Older Snippets »
Showing 1-7 of 7 total  RSS