Showing posts with label Web Development. Show all posts
Showing posts with label Web Development. Show all posts

Tuesday, 12 February 2013

Converting an Excel date into PHP timestamp

I was recently asked by a customer to upload a large dataset extracted from their old Microsoft Office based database system into their shiny new web-based application (Built by the guys at Zypher).

The data included a lot of date fields which needed to be converted into UNIX timestamp to be used by the PHP based front-end.

We used the formula below to convert the dates, it assumes the date is in cell ‘A2’.

=(A2-DATE(1970,1,1))*86400

I hope it proves useful.

Saturday, 19 November 2011

Using the Microsoft CDN or Google CDN for jQuery

As we develop new websites and try to introduce more user interactivity and animation effects it will become more frequent that we use some kind of JavaScript library.

Probably the most popular and most well-known is the jQuery library.  This post is going to show you how to link the library to your site.  We’ll also add a tip or two along the way.

For a jQuery tutorial click here for the w3schools page.

Adding the jQuery Library to Your Pages

The jQuery library is stored as a single JavaScript file, containing all the jQuery methods. It can be added to a web page with the following mark-up:

<head>
<script type="text/javascript" src="jquery.js"></script>
</head>

Remember that the <script> tag should be inside the page's <head> section. 

The above method requires you to download the jQuery file (see here) and store it on your server with your site.  Two versions of jQuery are available for downloading: one minified and one uncompressed (for debugging or reading).

Alternatively you can use a Content Delivery Network (CDN).  There are three CDNs available; jQuery CDN (via Media Temple), Google Ajax API CDN and the Microsoft CDN.

Google:
<script type="text/javascript" src=http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js>
</script>


Microsoft:
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js">
</script>

jQuery:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js”></script>

 

A couple of tips:

Monday, 31 October 2011

Variables in CSS File (Dynamic CSS)

Problem: Using CSS Variables/Dynamic CSS;

Firstly, I am aware that using variables in CSS seems to be topic for many a forum and blogs alike, W3C have not to my knowledge implemented variables in full within CSS as it breaks the segregation between Stylesheets and logic/script files (php etc).
Using variables is CSS has been somewhat of a minefield with entire articles and dedicated web pages on the matter. Not that these are bad in anyway, as they are, in the author's opinion, a way of producing the desired result. It is just my opinion which says these methods are, at time, very long winded and are quite 'fatty'.
Most requests for such variables in CSS are based around outputs from database queries, corporate colour schemes was my driving force and seems to be the case for the majority of reasons for the CSS variable request.
What i aim to provide with the solution i found, is a very lean and simple to use way of using variables within CSS styling.

Solution:
I come back and edit this in the near future and give you a working example of my colour scheme mySQL database table, create script and a site i used to generate the perfect tones that i required, but for now, this is the workings of "PCSS" (php CSS file).
  • Create a php file called PCSS.php
  • Paste this code into the file:
1:  <?php 
2:
3: $PCSS = getPCSS();
4: header("Content-type: text/css");
5: echo $PCSS;
6:
7:
8: ?>

  • Create a function called "getPCSS()" - Remember to insert this before the "?>" php closure tag.
  • Within the getPCSS function, write your db extract routine or variables you wish to dynamically use within a CSS file.
  • Save and close the file.
  • Open and edit the file that you wish to include the dynamic CSS within and point a new link to the new PCSS.php file (example: )
  • Thats it!
I said it wasn't going to be difficult, and in my opinion, this is the leanest way of producing the desired result.
The simple "header("Content-type: text/css");" tells the PHP file to return the content as CSS, which means you can have functions, variables, db queries etc within this file, but the return of function "getPCSS()" will pass CSS to the browser.

I could give you a bench mark, but to be honest, the results are subjective to the size of your PCSS.php file, subsequent db queries etc and performance will vary. However, with that said, an average time for my PCSS.php file to query 30 colours from 1 table, build 15 different CSS names/classes for each colour, which is around 1200 LOC, takes around 200ms.

As said, i will give you a working db example using a colour scheme which is the most common reason to require dynamic CSS (I didn't want to remember the 30 different colours and shades HTML colour codes).


If you think my post is good, or have any questions, please feel free to drop me a comment and I will get back to you.

Saturday, 9 April 2011

HTML Special Characters from 1 to 10000

In four fonts: Times New Roman, Arial, Courier New, and Comic Sans MS.

Blogger didn’t like the amount of code required to show the list of special characters so please click here to see the lists.  They are hosted on our main website.

Sunday, 14 November 2010

Website Design and Development

Hello again, it’s been a while since the last blog post so I thought it a good idea to show you what we’d been up to.

We’ve been working on a couple of websites, hope you like our work.

Websites_TeamMP3Websites_CakesByDianeWebsites_SilveroseWebsites_1stWickfordScouts

Some of the above are still a work in progress, but we hope they show a few options from the range of styles we have to offer.