You are here: PHP & Crontab « All PHP « IT news, forums, messages
PHP & Crontab

Posted by ScareCrowe on 09/02/05 15:26

Ok I don't think this is an issue with PHP itself, but I was wondering if
anyone has had similar problems and maybe a solution.
I have a script that queries mysql from an array with a limit of 1, creates
a list of items and writes to a file to be included across several domains.
The script itself is simple and when I browse to the page it works
correctly. However, when I set it up as a cronjob, each item is listed
twice??? I am unsure if this is something in PHP I am overlooking or
something about the cron. I have posted the whole script below.

<?
function compare($a, $b){
if($a['timestamp'] == $b['timestamp']){
return 0;
}
return($a['timestamp'] < $b['timestamp']) ? -1 : 1;
}
require 'mysql_connect_file';
$item_array = array('item1','item2','item3','item4','item5');

foreach($item_array as $entry){
$sql = "SELECT * FROM table WHERE item='".$entry."' AND soft_delete!='0'
ORDER BY timestamp ASC LIMIT 1";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
$the_array[] = $row;
}
}
usort($the_array, "compare");
$txtwrite = "<table cellpadding=\"1\" cellspacing=\"0\" width=\"125\"
style=\"border: 1px solid #000000;\">\n\n";
$txtwrite .= "\t<tr>\n\t\t<td align=\"center\"><img src='header.gif' alt=''
width='125' height=\"62\" border='0'></td>\n\t</tr>\n<tr
style=\"height:5px;\">\n\t\t<td> </td>\n\t</tr>\n";
for($z=0;$z<count($the_array);$z++){
switch($the_array[$z]['item']){
case"item1":
$siteurl = "http://www.domain1.com";
$mouseover = "Click Here To Visit Domain 1!";
break;
case"item2":
$siteurl = "http://www.domain2.com";
$mouseover = "Click Here To Visit Domain 2!";
break;
case"item3":
$siteurl = "http://www.domain3.com";
$mouseover = "Click Here To Visit Domain 3!";
break;
case"item4":
$siteurl = "http://www.domain4.com";
$mouseover = "Click Here To Visit Domain 4!";
break;
case"item5":
$siteurl = "http://www.domain5.com";
$mouseover = "Click Here To Visit Domain 5!";
break;
}
$txtwrite .= "\t<tr>\n\t\t<td align=\"left\" nowrap><a
href=\"".$siteurl."\"
style='font-family:Verdana;font-size:9px;color:#5C97C1;'
target=\"_blank\">". date("m/d @ hA",$the_array[$z]['timestamp'])."
".ucwords($the_array[$z]['item'])."</a></td>\n\t</tr>\n";
}
$txtwrite .= "\n<tr style=\"height:5px;\">\n\t\t<td>
</td>\n\t</tr>\n</table>\n</span>";
$write_file = "path_to_write_file";
$handle = fopen($write_file, "w");

if(!fwrite($handle, $txtwrite)){
$errmsg = "Could not write to file!";
urlencode($errmsg);
mail($to,$subject,$errmsg);
}
fclose($handle);
?>


Thanks in advance for checking!
--ScareCrowe

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация