Web Development
 
Your Ad Here
Create a dynamic rss xml feed with php class 
class RSSFeed {
// VARIABLES
// channel vars
var $channel_url;
var $channel_title;
var $channel_description;
var $channel_lang;
var $channel_copyright;
var $channel_date;
var $channel_creator;
var $channel_subject;
// image
var $image_url;
// items
var $items = array();
var $nritems;
// FUNCTIONS
// constructor
function RSSFeed() {
$this->nritems=0;
$this->channel_url='';
$this->channel_title='';
$this->channel_description='';
$this->channel_lang='';
$this->channel_copyright='';
$this->channel_date='';
$this->channel_creator='';
$this->channel_subject='';
$this->image_url='';
}
// set channel vars
function SetChannel($url, $title, $description, $lang, $copyright, $creator, $subject) {
$this->channel_url=$url;
$this->channel_title=$title;
$this->channel_description=$description;
$this->channel_lang=$lang;
$this->channel_copyright=$copyright;
$this->channel_date=date("Y-m-d").'T'.date("H:i:s").'+01:00';
$this->channel_creator=$creator;
$this->channel_subject=$subject;
}
// set image
function SetImage($url) {
$this->image_url=$url;
}
// set item
function SetItem($url, $title, $description) {
$this->items[$this->nritems]['url']=$url;
$this->items[$this->nritems]['title']=$title;
$this->items[$this->nritems]['description']=$description;
$this->nritems++;
}
// output feed
function Output() {
$output = '<?xml version="1.0" encoding="iso-8859-1"?>'."\n";
$output .= '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">'."\n";
$output .= '<channel rdf:about="'.$this->channel_url.'">'."\n";
$output .= '<title>'.$this->channel_title.'</title>'."\n";
$output .= '<link>'.$this->channel_url.'</link>'."\n";
$output .= '<description>'.$this->channel_description.'</description>'."\n";
$output .= '<dc:language>'.$this->channel_lang.'</dc:language>'."\n";
$output .= '<dc:rights>'.$this->channel_copyright.'</dc:rights>'."\n";
$output .= '<dc:date>'.$this->channel_date.'</dc:date>'."\n";
$output .= '<dc:creator>'.$this->channel_creator.'</dc:creator>'."\n";
$output .= '<dc:subject>'.$this->channel_subject.'</dc:subject>'."\n";
$output .= '<items>'."\n";
$output .= '<rdf:Seq>';
for($k=0; $k<$this->nritems; $k++) {
$output .= '<rdf:li rdf:resource="'.$this->items[$k]['url'].'"/>'."\n";
};
$output .= '</rdf:Seq>'."\n";
$output .= '</items>'."\n";
$output .= '<image rdf:resource="'.$this->image_url.'"/>'."\n";
$output .= '</channel>'."\n";
for($k=0; $k<$this->nritems; $k++) {
$output .= '<item rdf:about="'.$this->items[$k]['url'].'">'."\n";
$output .= '<title>'.$this->items[$k]['title'].'</title>'."\n";
$output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
$output .= '<description>'.$this->items[$k]['description'].'</description>'."\n";
$output .= '<feedburner:origLink>'.$this->items[$k]['url'].'</feedburner:origLink>'."\n";
$output .= '</item>'."\n";
};
$output .= '</rdf:RDF>'."\n";
return $output;
}
};

Use the class this way:

$myfeed = new RSSFeed();
$myfeed->SetChannel('http://www.yousite.com/site-feed.xml', 'Title of your site', 'description of your site', 'en-us', 'Copyright applies', 'author', 'type of site');
$myfeed->SetImage('http://www.yoursite.com/logo.gif');
//here is an example using mysql to receive information
$sql = "select id, title, content, date from table order by date desc";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {

$link = "http://www.yourstory.com/index.php?s=".$row[0];

//strip all html tags
$description = strip_tags($row[2]);

$myfeed->SetItem($link,$row[1],$description);
}

$out = $myfeed->output();
//you have two options, you can just echo the feed or same it as an xml file in your server

// echo $out;
$file = "site-feed.xml";
$fh = fopen($file,'w');
fwrite($fh,$out);
fclose($fh);

////End of code////
//Validate your rss feed: http://feedvalidator.org



[ add comment ] ( 8 views )   |  permalink  |   ( 3 / 207 )
Ajax calls using prototype 
Protoype is an excellent javascript framework that provides an easy way to make ajax calls.

Here is the sample code of how to make the call:

//first I am passing a variable that I call id, this would be the row id for the database table being used, for example: if I'm updating the record with the id of 4, I would call: javascript:dosomethingAjax('4');
//the id is passed to the file dosome.php that will handle whatever it is you are trying to do
//if you want to pass more variables through the ajax call you would use commas to separate them, for example: parameters: {u: id, name: 'John', age: 24}

function dosomethingAjax(id) {
var myAjax = new Ajax.Request('dosome.php',
{method: 'get', parameters: {u: id},
onComplete: handleResponse});
}
//once dosome.php gets processed, the ajax call is complete and the following function is called, in this case, I am putting the results inside a div with the id of displayResults
function handleResponse(transport) {
document.getElementById('displayResults').innerHTML = transport.responseText;
}

//here is how to setup the dosome.php

<?php
//the variable u is being passed by the ajax call listed above
$id = $_GET['u'];
//do something like update or insert or select
echo "Success!";
?>

[ add comment ] ( 23 views )   |  permalink  |  related link  |   ( 3 / 190 )
Form Select State & Show current selection 
In this very basic example, the form is going to the same page on submit, assigning the state value to a session and showing the current selection in the drop down.

<?php
$_SESSION['STATE'] = $_POST['STATE'];

$temp_st = "type".$_SESSION['STATE'];
$$temp_st = " selected";
?>

<form name="form" method="post" action="">
<select name="STATE" id="STATE"
<option value="AL"<?php echo $typeAL; ?>>Alabama</option>
<option value="AK"<?php echo $typeAK; ?>>Alaska</option>
<option value="AZ"<?php echo $typeAZ; ?>>Arizona</option>
<option value="AR"<?php echo $typeAR; ?>>Arkansas</option>
<option value="CA"<?php echo $typeCA; ?>>California</option>
<option value="CO"<?php echo $typeCO; ?>>Colorado</option>
<option value="CT"<?php echo $typeCT; ?>>Connecticut</option>
<option value="DE"<?php echo $typeDE; ?>>Delaware</option>
<option value="DC"<?php echo $typeDC; ?>>District of Columbia</option>
<option value="FL"<?php echo $typeFL; ?>>Florida</option>
<option value="GA"<?php echo $typeGA; ?>>Georgia</option>
<option value="HI"<?php echo $typeHI; ?>>Hawaii</option>
<option value="ID"<?php echo $typeID; ?>>Idaho</option>
<option value="IL"<?php echo $typeIL; ?>>Illinois</option>
<option value="IN"<?php echo $typeIN; ?>>Indiana</option>
<option value="IA"<?php echo $typeIA; ?>>Iowa</option>
<option value="KS"<?php echo $typeKS; ?>>Kansas</option>
<option value="KY"<?php echo $typeKY; ?>>Kentucky</option>
<option value="LA"<?php echo $typeLA; ?>>Louisiana</option>
<option value="ME"<?php echo $typeME; ?>>Maine</option>
<option value="MD"<?php echo $typeMD; ?>>Maryland</option>
<option value="MA"<?php echo $typeMA; ?>>Massachusetts</option>
<option value="MI"<?php echo $typeMI; ?>>Michigan</option>
<option value="MN"<?php echo $typeMN; ?>>Minnesota</option>
<option value="MS"<?php echo $typeMS; ?>>Mississippi</option>
<option value="MO"<?php echo $typeMO; ?>>Missouri</option>
<option value="MT"<?php echo $typeMT; ?>>Montana</option>
<option value="NE"<?php echo $typeNE; ?>>Nebraska</option>
<option value="NV"<?php echo $typeNV; ?>>Nevada</option>
<option value="NH"<?php echo $typeNH; ?>>New Hampshire</option>
<option value="NJ"<?php echo $typeNJ; ?>>New Jersey</option>
<option value="NM"<?php echo $typeNM; ?>>New Mexico</option>
<option value="NY"<?php echo $typeNY; ?>>New York</option>
<option value="NC"<?php echo $typeNC; ?>>North Carolina</option>
<option value="ND"<?php echo $typeND; ?>>North Dakota</option>
<option value="OH"<?php echo $typeOH; ?>>Ohio</option>
<option value="OK"<?php echo $typeOK; ?>>Oklahoma</option>
<option value="OR"<?php echo $typeOR; ?>>Oregon</option>
<option value="PA"<?php echo $typePA; ?>>Pennsylvania</option>
<option value="RI"<?php echo $typeRI; ?>>Rhode Island</option>
<option value="SC"<?php echo $typeSC; ?>>South Carolina</option>
<option value="SD"<?php echo $typeSD; ?>>South Dakota</option>
<option value="TN"<?php echo $typeTN; ?>>Tennessee</option>
<option value="TX"<?php echo $typeTX; ?>>Texas</option>
<option value="UT"<?php echo $typeUT; ?>>Utah</option>
<option value="VT"<?php echo $typeVT; ?>>Vermont</option>
<option value="VA"<?php echo $typeVA; ?>>Virginia</option>
<option value="WA"<?php echo $typeWA; ?>>Washington</option>
<option value="WV"<?php echo $typeWV; ?>>West Virginia</option>
<option value="WI"<?php echo $typeWI; ?>>Wisconsin</option>
<option value="WY"<?php echo $typeWY; ?>>Wyoming</option>
</select>
<input type="submit" name="Submit" value="Submit"/>
</form>

[ 3 comments ] ( 17 views )   |  permalink  |   ( 3 / 237 )
Validating numbers 
var digits="0123456789"
var temp


if (form.SSN3.value=="") {
alert("Please enter your Social Security Number.")
form.SSN3.focus();
return false;
}
for (var i=0;i<form.SSN3.value.length;i++){
temp=form.SSN3.value.substring(i,i+1)
if (digits.indexOf(temp)==-1){
alert("Only numbers are accepted in Social Security Number.")
form.SSN3.focus();
return false;
}
}


[ 1 comment ] ( 9 views )   |  permalink  |   ( 2.9 / 234 )
Date drop down for PHP forms 
// created by www.dpwebservices.net

function listbox_day ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($dayf=01;$dayf<=31;$dayf++) {
if ($default == $dayf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(d, mktime(0,0,0,0,$dayf,2000))."\" $selected class=\"field\">".date(j, mktime(0,0,0,0,$dayf,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_month ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($monthf=01;$monthf<=12;$monthf++) {
if ($default == $monthf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(m, mktime(0,0,0,$monthf,1,2000))."\" $selected class=\"field\">".date(M, mktime(0,0,0,$monthf,1,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_year ($name, $start, $end, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($yearf=$end;$yearf>=$start;$yearf--) {
if ($default == $yearf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"$yearf\" $selected class=\"field\">$yearf</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_hour ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($hourf=1;$hourf<=12;$hourf++) {
if ($default == $hourf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(h, mktime($hourf,0,0,0,0,2000))."\" $selected>".date(g, mktime($hourf,0,0,0,0,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_24hour ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($hourf=00;$hourf<=23;$hourf++) {
if ($default == $hourf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(H, mktime($hourf,0,0,0,0,2000))."\" $selected>".date(H, mktime($hourf,0,0,0,0,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_min ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($minf=00;$minf<=59;$minf++) {
if ($default == $minf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(i, mktime(0,$minf,0,0,0,2000))."\" $selected>".date(i, mktime(0,$minf,0,0,0,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_week ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
$weekx = '0';
for ($week_count=strftime("%U"); $week_count>=1; $week_count--) {
$weekx ++;
$str = '-'.$week_count.' week Monday';
if (($timestamp = strtotime($str)) === -1) {
$weekmsg = "The string ($str) is bogus";
} else {

$weekmsg = "Week ".$weekx." - ".date('F j',$timestamp);
$weekdate = date(m.'/'.d.'/'.y,$timestamp);

}
// echo $default; weekx to select the week
if ($default == $weekdate) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".$weekdate."\" $selected>".$weekmsg."</option>\n";
}
$result.="</select>\n";
return $result;
}

// onChange=\"MM_goToURL('parent','#');return document.MM_returnValue\"

function listbox_nummon ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($dayf=1;$dayf<=48;$dayf++) {
if ($default == $dayf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".$dayf."\" $selected>".$dayf."</option>\n";
}
$result.="</select>\n";
return $result;
}

/*
example of echos


<?php echo listbox_month("month", 7); ?> /
<?php echo listbox_day("day",23); ?> /
<?php echo listbox_year("year", 1994, 2003, 2001); ?>,&nbsp;
<?php echo listbox_hour("hour", 12); ?>:
<?php echo listbox_min("min", 00); ?>
);
<br>
<?php echo listbox_month("month2", 1); ?> /
<?php echo listbox_day("day2", 2); ?> /
<?php echo listbox_year("year2", 1994, date(Y), 2002); ?>,&nbsp;
<?php echo listbox_hour("hour2", 11); ?>:
<?php echo listbox_min("min2", 59); ?>

Below is to call the current "week - month day" back to week 1 in a pulldown menu...
echo listbox_week("week", strftime("%U"));

*/


[ add comment ] ( 7 views )   |  permalink  |   ( 3 / 185 )

<Back | 1 | 2 | 3 | 4 | Next> Last>>


Home | Portfolio | Hosting | Web Development | Contact Us
© 2007 dpwebservices.net. All right reserved.