Hi there everyone.
I have a script that has been written to generate a feed for sites that mine links to.
It is supposed to return all jobs from my mySQL database that have not expired.
No matter what I do I can only get it to display all jobs or no jobs at all.
The expiry date in the database is in this format 06/26/2009 (which cannot be changed in the database) as I am aware that it makes a difference.
If anyone can help me with this it would be massively appreciated.
<?php
include "development/StripAttributes.php";
$username = "***"; //Database Username
$password = "***"; //Database Password
$hostname = "0.0.0.0"; //Database Host
$dbname = "****"; //Database (or Catalog in MySQL parlance) name
$dbh = mysql_connect($hostname, $username, $password) or die("Could not connect to database server");
$selected = mysql_select_db($dbname, $dbh) or die("Database not found or problem connecting");
$result = mysql_query("SELECT expiry, position, postdate, jobref, salary, jobid, subcounty, country, description FROM jobs");
function stripchars($str)
{
$row = htmlentities("$str");
$row = ereg_replace(128, "€", $row); // Euro symbol
$row = ereg_replace(133, "…", $row); // ellipses
$row = ereg_replace(" ", " ", $row); // space
$row = ereg_replace("&", "&", $row); // and "&", "&",
$row = ereg_replace(8226, "″", $row); // double prime
$row = ereg_replace(8216, "'", $row); // left single quote
$row = ereg_replace(145, "'", $row); // left single quote
$row = ereg_replace(8217, "'", $row); // right single quote
$row = ereg_replace(146, "'", $row); // right single quote
$row = ereg_replace(8220, """, $row); // left double quote
$row = ereg_replace(147, """, $row); // left double quote
$row = ereg_replace(8221, """, $row); // right double quote
$row = ereg_replace(148, """, $row); // right double quote
$row = ereg_replace(8226, "•", $row); // bullet
$row = ereg_replace(149, "•", $row); // bullet
$row = ereg_replace(8211, "–", $row); // en dash
$row = ereg_replace(150, "–", $row); // en dash
$row = ereg_replace(8212, "—", $row); // em dash
$row = ereg_replace(151, "—", $row); // em dash
$row = ereg_replace(8482, "™", $row); // trademark
$row = ereg_replace(153, "™", $row); // trademark
$row = ereg_replace(169, "©", $row); // copyright mark
$row = ereg_replace(174, "®", $row); // registration mark
$row = ereg_replace("","’",$row);//fix SQL
$final = htmlentities("$row");
return $final;
}
// if the file exists already, delete it first to flush data
$xmlfeedfile = "rad.xml";
$filehandle = fopen($xmlfeedfile, 'w');
$itemLink = $fullurl.'/info_jobid_'. $b[jobid].'.html';
$xmlString = '<'.'?'.'xml version="1.0" encoding="ASCII" '.'?' .'>
<source>
<publisher>***.co.uk</publisher>
<publisherurl>http://www.***.co.uk</publisherurl>';
fwrite($filehandle, $xmlString);
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$pos = stripslashes(strip_tags($row['position']));
$date = stripslashes(strip_tags($row['postdate']));
$ref = stripslashes(strip_tags($row['jobref']));
$desc = stripslashes(strip_tags($row['description']));
$cnt = stripslashes(strip_tags($row['country']));
$sal = stripslashes(strip_tags($row['salary']));
$loc = stripslashes(strip_tags($row['subcounty']));
$jid = stripslashes($row['jobid']);
$desc = preg_replace('/ /', ' ', $desc);
$desc = preg_replace('/&/', '/&/', $desc);
$desc = preg_replace("/'/", "'", $desc);
$desc = preg_replace('/#/', '£', $desc);
$pos = preg_replace('/ /', ' ', $pos);
$pos = preg_replace('/&/', '/&/', $pos);
$xmlString = "<job>\n\t<title><![CDATA[{$pos}]]></title>\n\t<date><![CDATA[{$date}]]></date>\n\t<referencenumber><![CDATA[{$ref}]]></referencenumber>\n\t<salary>{$sal}</salary>\n\t<url><![CDATA[http://www.editorialjobs.co.uk/info_jobid_{$jid}.html]]></url>\n\t<city><![CDATA[{$loc}]]></city>\n\t<country><![CDATA[{$cnt}]]></country>\n\t<description><![CDATA[{$desc}]]></description>\n</job>";
fwrite($filehandle, $xmlString);
}
mysql_close($dbh);
fwrite($filehandle, "</source>");
fclose($filehandle);
?>