Client Login



Blog

Food for thought and inspiring minds

January 08, 2010

Quick RSS Feed example

Here’s a quick way to get your site running with it’s own RSS feed. You rarely see a site without one!

<?php
header('Content-type: text/xml'); //change file type to XML
include("the database!");  //get config
?>
<rss version="2.0">
<channel>
 <title>Feed Name</title>
 <description>Feed Descriptiondescription>
 <link>http://yoursite.com</link>
<?php
$result = mysql_query("SELECT * FROM entries ORDER BY id DESC"); //get the information
while($row = mysql_fetch_assoc($result)){ //repeat the info
?>
<item>
 <title><?php echo $row['title']; //echo the title
?></title>
 <description><?php echo $row[short]; //echo the content
?></description>
 <author>SiteName submissions@yoursite.com</author>
 <link>http://yoursite.com/index.php?id=<?php echo $row['id']; //another link to the article
?></link>
 <guid>http://yoursite.com/#<?php echo $row[id];// Quick Link
?></guid>
</item>
<?
} //end the while
?>
</channel>
</rss>

Special thanks for runnerjp who supplied the above code!


December 27, 2009

Functional usage of jQuery to replace PHP

For the longest time, I’ve been using PHP to alternate rows when displaying data in a grid. I stumbled across this neat little site that adds a bit more to tables (or divs for you savvy css designers)

How to use the zebra striping layout via a tutorial and demo

I’ll never go back to the old methods as this will take some processing off the server.


August 01, 2009

PHP date essentials

In my projects, I’m always using dates, but to make life easier, I’ve composed a list of the dates I use to help reference by name rather than by the code.

<?php
$today = strtotime('today');
$yesterday = strtotime( '-1 days' );
$beforeyesterday = strtotime('-2 days');
$lastweek = strtotime('-7 days');
$lastmonth = strtotime('-30 days');
$lastyear = strtotime('-365 days');
$showtoday = date('M d');
$showyesterday = date('M d', $yesterday);
$showweek = date('M d', $lastweek);
$showmonth = date('M', $lastmonth);
$showyear = date('Y', $lastyear);
$now = time();
?>

I hope this is helpful for other PHP coders out there.


February 27, 2009

Convert US states from abbreviations to full name

This is a real time saver just to convert the abbreviation to a full name. I made this function and always use it in my projects. read more …


February 23, 2009

Convert month name to a number

For the longest time, I’ve always come across this barrier. No pun intended. I wish there was an easier way to convert the month name to a number, but after searching, I came across this thanks to doodlebee from webmasterworld.

Here’s what we have as follows, just copy and paste it and obviously change the month name to whatever month you need and it’ll show up.

function getMonth($m) {
$monthnames = array(
01 => 'January',
02 => 'February',
03 => 'March',
04 => 'April',
05 => 'May',
06 => 'June',
07 => 'July',
08 => 'August',
09 => 'September',
10 => 'October',
11 => 'November',
12 => 'December');

for($i=1;$i<=12;$i++){
$i = sprintf("%02d",$i);
if(date("F", mktime(0, 0, 0, $i, 1, 0)) == $m){
$month_number = $i;
}
}
return $month_number;
}//end function

echo getMonth('March');
echo getMonth('December');

And vice versa

function getMonthNum($m) {
$monthnames = array(
'01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December');

return $monthnames[$m];
}//end function

echo getMonthNum('09');