Archive for the ‘Script snippet’ Category

Date Time

Tuesday, September 9th, 2003

Just wanted to store some code I use a lot and am tired of looking up ;-)
In some of the scripts I work on, I create a field for a timestamp. For that field I insert the PHP value: time()

When recalling that value, it’s just an ugly looking UNIX timestamp, so to format it to something nice, I do the following: (as posted on the PHP manual)

<?php
/*
Assuming the UNIX timestap was for : March 10th, 2001, 5:16:18 pm
and you already did a mysql query, and fetch_array
and the name of the field for timestamp, is ‘timestamp’
*/
$today = date(”F j, Y, g:i a”, $row['timestamp']);
// March 10, 2001, 5:16 pm
$today = date(”m.d.y”, $row['timestamp']);
// 03.10.01
$today = date(”Ymd”, $row['timestamp']);
// 20010310
$today = date(’\i\t \i\s \t\h\e jS \d\a\y.’, $row['timestamp']);
// It is the 10th day.
$today = date(”D M j G:i:s T Y”, $row['timestamp']);
// Sat Mar 10 15:16:08 MST 2001
?>

Using php to selectively show or hide content based on MT category

Saturday, September 6th, 2003

All of you people that actually know PHP may want to skip this entry as what I’m about to say will probably make you cringe. You could probably do this in some frightfully easy way, but I’ve barely cracked my PHP book open, so this has to work for me for now.
(more…)

Get an email when Google visits

Wednesday, July 16th, 2003

When googlebot comes (if it does!) to pages that contains this code, you get an e-mail sent to the address you specify.
(more…)

Reset Skin Preference Cookie

Tuesday, June 17th, 2003

Originally posted at http://blog.kevindonahue.com

I presented Jennifer with a question: How do I remove skins? or –to be more specific– How do I let users delete their skin preferences and use the current default?
(more…)

PHP: What’s coming in from the form?

Tuesday, June 10th, 2003

I posted how to do this in ASP, but since I needed something similar in PHP for that last post, I thought I’d post the PHP version as well.

This script snippet will play back everything that was just submitted in the form (code found in the each function page in the PHP manual.)
(more…)

Secondary form that populates a main form

Tuesday, June 10th, 2003

Let’s say you have some optional items to your form. (Maybe extra address info) and your form is long enough as it is. You can pop up a secondary form, where the user can enter their extra info, and have it saved to the main form and submitted with the main form. (see example here)
(more…)

ASP: A template that will show all data from a table (including header rows)

Monday, June 2nd, 2003

I talked about stored procedures here the other day. Today, I needed to create a page that would call one of those stored procedures (the selecting one) and display all data from a table. This code is very plug-and-play-ish - very little needs to be modified (that is, as long as you’re using MS SQL Server). If all you need to do is a “screen dump” of everything in the table, this ASP takes care of everything for you… (it even uses an ASP version of the alternating color rows PHP script snippet I had posted awhile back here.
(more…)

writing and using stored procedures

Saturday, May 31st, 2003

I’ve been learning about stored procedures and calling them from ASP pages. So just wanted to jot down some examples/templates…

(note from my technical editor, Mike: This code is specific to MS SQL Server and probably wouldn’t work with other databases.)
(more…)

ASP: What’s coming from the form?

Thursday, May 15th, 2003

A simple little ASP snippet. If you want to see what’s coming over from your method=”POST” form - here’s a bit of code that will loop through everything, show you the variable name and it’s value:

for each x in request.form()
response.write(x & “: ” & request.form(x) & “<br>” )
next

if you’re using method=”GET” then it would be:

for each x in request.querystring()
response.write(x & “: ” & request.querystring(x) & “<br>” )
next

Another way to manage links

Sunday, May 11th, 2003

Back when I first changed the format of my page so that I had the same list of links down the side of every page, I quickly discovered that it was a pain to have to go through 5 or 6 pages of HTML/PHP adding new links here and there.

I eventually came up with a system that makes it much easier to add/remove links from all my pages in a single go. On every page that has a list of links, I put this at the top:

include “path/to/linkage.inc”;

The file linkage.inc contains a series of multidimensional arrays, like so:

$blogsLinkage = array(
0 => array(”http://www.snazzykat.com/”, “snazzykat”),
1 => array(”http://www.scriptygoddess.com/”, “Scriptygoddess”),
2 => array(”http://www.technoerotica.net/”, “technoerotica”),
4 => array(”http://www.neuroticfishbowl.com/”, “neurotic fishbowl”),
5 => array(”http://www.tampatantrum.com/”, “aint too proud to blog”),
7 => array(”http://troll54.blogspot.com/”, “Troll54″),
8 => array(”http://timatollah.blogspot.com/”, “Timatollah”),
9 => array(”http://www.greasypants.org/”, “greasypants”),
10 => array(”http://www.randomramblings.com/”, “Random Ramblings”),
);

$techLinkage = array(
0 => array(”http://www.thinkgeek.com/”, “ThinkGeek”),
1 => array(”http://www.phpbuilder.com/”, “PHP Builder”),
2 => array(”http://www.scriptygoddess.com/”, “scriptygoddess”),
3 => array(”http://www.dynamicdrive.com/”, “Dynamic Drive”),
);

Then, in each file where the links are to be listed, it’s a simple matter of a nice little loop to render the code:

<?php
foreach ($blogsLinkage as $val) {
print “<a href=\”$val[0]\”>$val[1]</a><br />”;
}
?>
[more HTML code...]
<?php
foreach ($techLinkage as $val) {
print “<a href=\”$val[0]\”>$val[1]</a><br />”;
}
?>

Then, whenever I need to add a new link, I simply put a new entry into linkage.inc. If I need to remove a link, simply take it out of linkage.inc. This way, all the pages are updated automatically, and it’s much easier!

Guest authored by:
Will - silverfisch.net