Archive for August, 2005

Another function I constantly check on and use, especially when dealing with dates, working out if one has passed usually. The function mktime() does this simply. Let's say you've got a form, 3 select boxes, one for each of the day, month and year (never rely on people inputting the date in the correct format for you, always control it!). So you take in 3 POST variables, to calculate whether it's before or after today you just need the following:

<?php
$givendate = mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']);
$today = mktime(0, 0, 0, date("m"), date("d"), date("Y"));

if ($givendate < $today) {
print "The date has passed";
} else {
print "The date hasn't passed";
}
?>

Yes there are a far wider range of uses for this functions, but it's one I constantly use for the reason above (well I use it a little more advanced than that but it's basically the same!).

I know a few of the lesser used pages will be out but I really have to get some work done. The main front page and the comments pages are not breaking. I still want to reorder the menu (anyone know how to do this without hacking the function to pieces? I just want it displayed by hierarchy), and fix the other pages.

Anything major let me know and I'll get that fixed, but time to actually do some paid for work!

Have spent most of the weekend not working but doing a new design for this site. I spent last night writing the CSS and editing the templates. Just have to get the divs in the right places and then it should be ready. So if you do happen to be here and it looks badly broken it's me just switching between the themes! Don't get me wrong, it's not fantastic, I'm not a designer, but this isn't a commercial venture either so doesn't warrant a professional design.

Really however should do some work.

I keep looking this up on the PHP site because I can never remember the syntax so I figured I'd add it here. A simple operator that cuts down on code and can be used inline with print statements…

<?php print "if the variable i is equal to 1 ". ($i==1 ? "message 1" : "message 2"); ?>

What does it mean? It's a simple if statement with a one line result for each option. It basically says if the variable i is equivalent to the value 1 ($i==1) then the first output "message 1" will be displayed on screen, otherwise the second output, "message 2" will be displayed. The following does the same:

<?php
print "if the variable i is equal to 1 ";
if ($i==1) {
print "message 1";
} else {
"message 2";
}
?>

As you can see the first way uses a lot less code! Why is it handy? Well I'm currently adding a column to a report for a web site. Some of their products are also displayed on eBay and they want to be able to tick a box in the stock info to tell them whether it's on eBay or not. Of course the report then says Y or N. However for faster access it's better to use 0 and 1 in the table, 1 meaning Y. So in my form I just have

print "<td>".($row['ebay']==1 ? "Y" : "N")."</td>";

Which basically says if the value is 1 then display Y else display N. Much quicker and cleaner!

Yesterday I started to upgrade the software used for this site finally. The old b2 software was great but I've been told WordPress has more features and easier to customise so I figured I'd use it. Plus b2 is no longer being supported which means no fixes etc.

So you'll see bits which don't look right, and the template still needs customising. Plus anyone with the old RSS feed will need to update to the new one (sorry!).

If you see anything that doesn't look right let me know, I may have missed it off my to do list.

Page 1 of 212»

Latest Tweets