...

View Full Version : Resolved how do i create a CRON job which deleted my entire data table and inserts new data?



LJackson
05-06-2009, 02:13 AM
Hi all,

I'veherd a little about CRON jobs but dont really know anything about them apart fom that i can use them to periodically update things?

i have a table which holds data from several rss feeds and i want the data updated every hour but im not sure how i could do this :(

here is the code i currently have to insert the data into the table, but it keeps inserting new data so i need to clear the table first?

<?php
$user_name = "";
$password = "";
$database = "";
$server = "";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

$feeds = array(...);

$itemno = 1;
$itemtype = 0;

foreach ($feeds as $feed){
$count = 2;

$feedreader = simplexml_load_file
("$feed");
foreach ($feedreader->channel->item as $item) {
$title = addslashes ($item->title);
$photosource = get_string_between($item->description, '<img src="','"');
if($count >= 0){

if($itemno<=45){
$itemtype = "Books";
}
if($itemno<=36){
$itemtype = "Blu-Ray";
}
if($itemno<=27){
$itemtype = "Video Games";
}
if($itemno<=18){
$itemtype = "CD";
}
if($itemno<=9){
$itemtype = "DVD";
}


if
($itemno >=1 && $itemno <=3 || $itemno >=10 && $itemno <=12 ||
$itemno >=19 && $itemno <=21 || $itemno >=28 && $itemno <=30 ||
$itemno >=37 && $itemno <=39){
$subcat = "Bestsellers";
}
elseif
($itemno >=4 && $itemno <=6 || $itemno >=13 && $itemno <=15 ||
$itemno >=22 && $itemno <=24 || $itemno >=31 && $itemno <=33 ||
$itemno >=40 && $itemno <=42){
$subcat = "New Releases";
}
elseif
($itemno >=7 && $itemno <=9 || $itemno >=16 && $itemno <=18 ||
$itemno >=25 && $itemno <=27 || $itemno >=34 && $itemno <=36 ||
$itemno >=43 && $itemno <=45){
$subcat = "Gifted";
}


$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other) VALUES ('Entertainment','$itemtype', '$subcat', '$title', '$photosource', 'other')";
$sql = mysql_query($insert);
$count --;
$itemno ++;
}
}
}
?>


but thats all i know...

the rest is in your hands :D

cheers
Luke

nobackseat88
05-06-2009, 02:42 AM
I would actually like to know about this additionally...

*lurks*

:thumbsup:

Sorry I don't have any info, except that the code you currently have looks good.

Consider this a bump

_Aerospace_Eng_
05-06-2009, 03:11 AM
As long as the user for your mysql database has the permission to, you can use TRUNCATE
Before this

$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other) VALUES ('Entertainment','$itemtype', '$subcat', '$title', '$photosource', 'other')";
$sql = mysql_query($insert);
add this

mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other) VALUES ('Entertainment','$itemtype', '$subcat', '$title', '$photosource', 'other')";
$sql = mysql_query($insert);

masterofollies
05-06-2009, 03:41 AM
If you have a control panel, you can easily setup cron jobs there. Just set the path to the file, and type in when to update it.

_Aerospace_Eng_
05-06-2009, 02:23 PM
Cron jobs can be run on apache easily as stated through CPanel or other similar control panels. If you are on a windows server you need to use the task scheduler. And finally if you can't do either of those then you can use what is called an "lazy man's" cron job which is essentially including that file into pages on your site that get the most traffic. You'll basically have the user run the file without then really knowing unless you are inserting a lot of data in which case page load might increase.

LJackson
05-06-2009, 03:27 PM
I would actually like to know about this additionally...

*lurks*

:thumbsup:

Sorry I don't have any info, except that the code you currently have looks good.

Consider this a bump

You Lurker You :D
and thanks...

LJackson
05-06-2009, 03:32 PM
As long as the user for your mysql database has the permission to, you can use TRUNCATE
Before this

$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other) VALUES ('Entertainment','$itemtype', '$subcat', '$title', '$photosource', 'other')";
$sql = mysql_query($insert);
add this

mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other) VALUES ('Entertainment','$itemtype', '$subcat', '$title', '$photosource', 'other')";
$sql = mysql_query($insert);

Hi Aerospace, thanks for this yeah i have allowed access to my database so this wont be a problem :)

Can You please elaborate on the Setup of a CRON Job,

sorry this is all new to me and im not sure i follow you :)
when you are talking about the server is that my hosts server? how do i tell if its windows or apache?

sorry for all the questions :)
many thanks
Luke

LJackson
05-06-2009, 03:34 PM
If you have a control panel, you can easily setup cron jobs there. Just set the path to the file, and type in when to update it.

Hi masterofollies,

i assume when talking about control panel you mean when i sign in to my host and access their control panel?

my host is one.com i will have a look on their control pannel to see if there is an option :)

thanks
Luke

LJackson
05-06-2009, 03:38 PM
i have just checked out my hosts control panel and i cannot see anywhere with the option to create a cron job :(

i assume you mean my own pcs control panel as i have just found task scheduler :)

so do i simply save that file (i want to run) to my webspace? or on my machine? and then set up a new task which will run that script every hour?

thanks
Luke

_Aerospace_Eng_
05-06-2009, 03:45 PM
Cron jobs can only be run on apache servers which is how you will know. A scheduled task similar to a cron job runs on windows servers. I suggest you contact your host. As to what to do with the file you put it on your webhost. How do you expect it to even work if you run it on your own computer?

LJackson
05-06-2009, 04:05 PM
lol ok so....

i need to find out which sort of server my host is running to determin which route i take???

if its a widows host then i can simple set up a new task on my computer which will run my file stored on my hosts server???

if its an apache server im still unsure what to do :( sorry!!!!

but i will contact my host and see what type of server it is first then if need be we can cross the apache bridge if needed :)

thanks
Luke

LJackson
05-06-2009, 04:13 PM
ok just contacted my host and they said CRON is not supported :(
so i assume its a windows based server.

i also asked if i could use the task sheduler to perform the task and was told "well if it does not require cron then it is fine"

_Aerospace_Eng_
05-06-2009, 04:22 PM
Okay so cron is out of the question. Put the file on your server somewhere. Since it probably doesn't matter who runs the file it is probably okay to put it in the public directory. Read this article

http://www.hiveminds.co.uk/?p=35223

LJackson
05-06-2009, 04:30 PM
ok thanks i have copied the file to my host and can be located at www.kernow-connect.com/dbupdater.php

i will read that link you provided to try and set up a task sheduler :)

i may be back for some more assistance soon :P

cheers for all your help so far
Luke

LJackson
05-06-2009, 04:55 PM
ok

i currently have

Call LogEntry()

Sub LogEntry()

'Force the script to finish on an error.
On Error Resume Next

'Declare variables
Dim objRequest
Dim URL

Set objRequest = CreateObject("Microsoft.XMLHTTP")

'Put together the URL link appending the Variables.
URL = "http://www.kernow-connect.com/dbupdater.php"

'Open the HTTP request and pass the URL to the objRequest object
objRequest.open "GET", URL , false

'Send the HTML Request
objRequest.Send

'Set the object to nothing
Set objRequest = Nothing

End Sub

saved as updater_script.vbs

and my php code

<?php
$user_name = "";
$password = "";
$database = "";
$server = "";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$feeds = array(
"http://www.amazon.co.uk/rss/bestsellers/dvd/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/new-releases/dvd/ref=pd_nr_rss_link","http://www.amazon.co.uk/rss/most-gifted/dvd/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/music/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/music/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/music/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/videogames/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/videogames/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/videogames/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/dvd/383380011/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/dvd/383380011/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/dvd/383380011/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/books/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/books/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/books/ref=pd_mw_rss_link"
);

$itemno = 1;
$itemtype = 0;

foreach ($feeds as $feed){
$count = 2;

$feedreader = simplexml_load_file
("$feed");
foreach ($feedreader->channel->item as $item) {
$title = addslashes ($item->title);
$photosource = get_string_between($item->description, '<img src="','"');
if($count >= 0){

if($itemno<=45){
$itemtype = "Books";
}
if($itemno<=36){
$itemtype = "Blu-Ray";
}
if($itemno<=27){
$itemtype = "Video Games";
}
if($itemno<=18){
$itemtype = "CD";
}
if($itemno<=9){
$itemtype = "DVD";
}


if
($itemno >=1 && $itemno <=3 || $itemno >=10 && $itemno <=12 ||
$itemno >=19 && $itemno <=21 || $itemno >=28 && $itemno <=30 ||
$itemno >=37 && $itemno <=39){
$subcat = "Bestsellers";
}
elseif
($itemno >=4 && $itemno <=6 || $itemno >=13 && $itemno <=15 ||
$itemno >=22 && $itemno <=24 || $itemno >=31 && $itemno <=33 ||
$itemno >=40 && $itemno <=42){
$subcat = "New Releases";
}
elseif
($itemno >=7 && $itemno <=9 || $itemno >=16 && $itemno <=18 ||
$itemno >=25 && $itemno <=27 || $itemno >=34 && $itemno <=36 ||
$itemno >=43 && $itemno <=45){
$subcat = "Gifted";
}
print "$itemno equals $itemtype subcat equals $subcat";
print "<br />";


mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other) VALUES ('Entertainment','$itemtype', '$subcat', '$title', '$photosource', 'other')";
$sql = mysql_query($insert);

$count --;
$itemno ++;
}
}
}
?>

so is that all ok, i just need to set up the task sheduler now which is explained in the link you provided :)

cheers

LJackson
05-06-2009, 05:02 PM
ok setting up the task sheduler

ive give it a name and description, where it says run if user is logged on or if user is logged on or off i've chosen on or off

where it says dont store p/w i havent ticked

do i run it with highest privilages???

i have set it to start at 5.30pm today and run every hour i have also selected the radio button "one time", i have set the vbs script in the actions, and the conditions i have un ticked everything does this sound ok???

sorry again for the questions best to be safe and get it right :)

cheers
Luke

LJackson
05-06-2009, 05:14 PM
right i have set it up as above can only wait and see if it works :)

LJackson
05-06-2009, 05:44 PM
ok i have ran the vbs script by loading it im the browser and i get the code come up


Call LogEntry()

Sub LogEntry()

'Force the script to finish on an error.
On Error Resume Next

'Declare variables
Dim objRequest
Dim URL

Set objRequest = CreateObject("Microsoft.XMLHTTP")

'Put together the URL link appending the Variables.
URL = "http://www.kernow-connect.com/dbupdater.php"

'Open the HTTP request and pass the URL to the objRequest object
objRequest.open "GET", URL , false

'Send the HTML Request
objRequest.Send

'Set the object to nothing
Set objRequest = Nothing

End Sub

but nothing happens to the db nothig is deleted nor added :( any ideas why this is?

cheers
Luke

LJackson
05-06-2009, 09:30 PM
it also keeps failing the sheduled task

not sure why this wont work probably something simple as always :D

any ideas
Luke

_Aerospace_Eng_
05-06-2009, 09:44 PM
Why are you using a vbs script? The article I posted has you using wget and then just calling your php script.

LJackson
05-06-2009, 10:00 PM
Hi mate, is that not for Linux? if followed the windows steps (i think)

i does have a link which says
"Now if you are like me you are always looking for an alternative method, a back up for when things go horribly wrong. In this case I have discovered that there is in fact a Windows port of of the Linux wget program. Using this is pretty simple, is an easier process to kill and it does have a smaller foot than IE or Firefox. But still it does take resources and so I will put this on the back burner for later experimentation."

cheers
Luke

_Aerospace_Eng_
05-06-2009, 11:06 PM
You did follow the windows steps but did you keep reading? Try the wget method by downloading the port of the linux version.

LJackson
05-06-2009, 11:55 PM
ok i will try that :)

thanks
Luke

LJackson
05-07-2009, 12:13 AM
ok mate i have downloaded the file and have the command prompt window open but im stuck on what to do next there is nothing on the download page which i understand or which i think will help?

would this be right?

wget.exe -q -O nul http://www.kernow-connect.com/dbupdater.php

and what do i do next?

thank you
Luke

_Aerospace_Eng_
05-07-2009, 01:11 AM
Yeah thats right, now schedule a task to run wget.exe with the parameters you have set.

LJackson
05-07-2009, 01:29 AM
sorry mate i dont follow :(


wget.exe -q -O nul http://www.kernow-connect.com/dbupdater.php

what do the -q -O nul mean??????

and do i insert all of this into the actions? and then set the time intervals as normal?

sorry for being a pain in the backside i'll get there one day :)
cheers

_Aerospace_Eng_
05-07-2009, 03:19 AM
Don't worry about what they mean. They aren't important. Add wget.exe as the program to start then add in the rest as the arguments to use.

LJackson
05-07-2009, 02:22 PM
i've done that mate, but it keeps failing :( not sure why though?

any ideas??

thanks
Luke

i have copied my wget.exe to the windows folder and if i double click on it it flashes up a black screen for a second then thats it, nothing actually opens???

LJackson
05-07-2009, 02:32 PM
ah ok it now seems to be running :)

i will check to see if the db is updating, think what i will do is add a new colum which stores the last update time/date so i can tell when it last updated....

LJackson
05-07-2009, 03:23 PM
hi mate, it seems to be working :)

thank you very much for your help and for sticking with it because i couldnt of done it with out you :)

cheers
Luke

_Aerospace_Eng_
05-07-2009, 04:12 PM
So what was the problem? Also wget really wasn't supposed to open anything. It was just supposed to call that url so it runs.

LJackson
05-07-2009, 04:23 PM
i think its because i extracted the exe to my downloads and not to the windows folder :)

LJackson
05-08-2009, 02:30 PM
Hi mate, little problem nothing major but is it possible to get the wget to run even if the computer is turned off, i have set the preferences to run if the pc is on or off but it doesnt run if turned off...

would i need to enable the scheduler to power up the pc and would it power off again once its finished?

thanks
Luke

_Aerospace_Eng_
05-08-2009, 04:59 PM
yes that is what you need to do. How can your pc run something if its off?

LJackson
05-08-2009, 05:06 PM
lol ok... not very practical thought to have the pc turn on every hour :(

thanks for clearing that up
luke

LJackson
05-13-2009, 05:24 PM
Hi,

i am trying to insert more info into my db via this task shedule but for some starnge reason it only inserts the first 127 rows into the db when there should be around 150?

its a bit odd, is there any limit to this?

here is my code

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());

function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

$today = date("d-M-Y, h:i a");

//Entertainment Update
$feeds = array(
"http://www.amazon.co.uk/rss/bestsellers/dvd/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/new-releases/dvd/ref=pd_nr_rss_link","http://www.amazon.co.uk/rss/most-gifted/dvd/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/music/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/music/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/music/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/videogames/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/videogames/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/videogames/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/dvd/383380011/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/dvd/383380011/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/dvd/383380011/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/books/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/books/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/books/ref=pd_mw_rss_link"
);

$itemno = 1;
$itemtype = 0;

foreach ($feeds as $feed){
$count = 2;

$feedreader = simplexml_load_file
("$feed");
foreach ($feedreader->channel->item as $item) {
$title = addslashes ($item->title);
$photosource = get_string_between($item->description, '<img src="','"');
$otherinfo = get_string_between($item->description, '<span class="riRssContributor">','</span>');
if($count >= 0){

if($itemno<=45){
$itemtype = "Books";
}
if($itemno<=36){
$itemtype = "Blu-Ray";
}
if($itemno<=27){
$itemtype = "Video Games";
}
if($itemno<=18){
$itemtype = "CD";
}
if($itemno<=9){
$itemtype = "DVD";
}


if
($itemno >=1 && $itemno <=3 || $itemno >=10 && $itemno <=12 ||
$itemno >=19 && $itemno <=21 || $itemno >=28 && $itemno <=30 ||
$itemno >=37 && $itemno <=39){
$subcat = "Bestsellers";
}
elseif
($itemno >=4 && $itemno <=6 || $itemno >=13 && $itemno <=15 ||
$itemno >=22 && $itemno <=24 || $itemno >=31 && $itemno <=33 ||
$itemno >=40 && $itemno <=42){
$subcat = "New Releases";
}
elseif
($itemno >=7 && $itemno <=9 || $itemno >=16 && $itemno <=18 ||
$itemno >=25 && $itemno <=27 || $itemno >=34 && $itemno <=36 ||
$itemno >=43 && $itemno <=45){
$subcat = "Gifted";
}

$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other, lastUpdated) VALUES ('Entertainment','$itemtype', '$subcat', '$title', '$photosource', '$otherinfo', '$today')";
$sql = mysql_query($insert);

$count --;
$itemno ++;
}
}
}



//COMPUTING UPDATE
$feeds2 = array(
"http://www.amazon.co.uk/rss/bestsellers/electronics/14014421/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/14014421/ref=pd_nr_rss_link","http://www.amazon.co.uk/rss/most-gifted/electronics/14014421/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/electronics/14014431/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/14014431/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/electronics/14014431/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/electronics/120100031/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/120100031/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/electronics/120100031/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/10392741/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/10392741/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/10392741/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/296746011/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/561940/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/296746011/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/software/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/software/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/software/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/561904/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/561904/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/561904/ref=pd_mg_rss_link",
);

$itemno = 1;
$itemtype = 0;

foreach ($feeds2 as $feed){
$count = 2;

$feedreader = simplexml_load_file
("$feed");
foreach ($feedreader->channel->item as $item) {
$title = addslashes ($item->title);
$photosource = get_string_between($item->description, '<img src="','"');
$otherinfo = get_string_between($item->description, '<span class="riRssContributor">','</span>');
if($count >= 0){



if($itemno<=63){
$itemtype = "Accessories";
}
if($itemno<=54){
$itemtype = "Software";
}
if($itemno<=45){
$itemtype = "Scanner";
}
if($itemno<=36){
$itemtype = "Printer";
}
if($itemno<=27){
$itemtype = "Netbook";
}
if($itemno<=18){
$itemtype = "Notebook";
}
if($itemno<=9){
$itemtype = "Desktop";
}


if
($itemno >=1 && $itemno <=3 || $itemno >=10 && $itemno <=12 ||
$itemno >=19 && $itemno <=21 || $itemno >=28 && $itemno <=30 ||
$itemno >=37 && $itemno <=39 || $itemno >=46 && $itemno <=48 ||
$itemno >=55 && $itemno <=57){
$subcat = "Bestsellers";
}
elseif
($itemno >=4 && $itemno <=6 || $itemno >=13 && $itemno <=15 ||
$itemno >=22 && $itemno <=24 || $itemno >=31 && $itemno <=33 ||
$itemno >=40 && $itemno <=42 || $itemno >=49 && $itemno <=51 ||
$itemno >=58 && $itemno <=60){
$subcat = "New Releases";
}
elseif
($itemno >=7 && $itemno <=9 || $itemno >=16 && $itemno <=18 ||
$itemno >=25 && $itemno <=27 || $itemno >=34 && $itemno <=36 ||
$itemno >=43 && $itemno <=45 || $itemno >=52 && $itemno <=54 ||
$itemno >=61 && $itemno <=63){
$subcat = "Gifted";
}

$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other, lastUpdated) VALUES ('Computing','$itemtype', '$subcat', '$title', '$photosource', '$otherinfo', '$today')";
$sql = mysql_query($insert);

$count --;
$itemno ++;
}
}
}

//Electronics Update

$feeds3 = array(
"http://www.amazon.co.uk/rss/bestsellers/electronics/14210121/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/14210121/ref=pd_nr_rss_link","http://www.amazon.co.uk/rss/most-gifted/electronics/14210121/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/electronics/1062130/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/1062130/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/electronics/1062130/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/electronics/492731011/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/492731011/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/electronics/492731011/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/573372/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/573372/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/573372/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/560836/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/560836/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/560836/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/4085991/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/4085991/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/4085991/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/560860/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/560860/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/560860/ref=pd_mg_rss_link",
);

$itemno = 1;
$itemtype = 0;

foreach ($feeds3 as $feed){
$count = 2;

$feedreader = simplexml_load_file
("$feed");
foreach ($feedreader->channel->item as $item) {
$title = addslashes ($item->title);
$photosource = get_string_between($item->description, '<img src="','"');
$otherinfo = get_string_between($item->description, '<span class="riRssContributor">','</span>');
if($count >= 0){



if($itemno<=63){
$itemtype = "DVD Players";
}
if($itemno<=54){
$itemtype = "Home Cinema Systems";
}
if($itemno<=45){
$itemtype = "Digital Cameras";
}
if($itemno<=36){
$itemtype = "MP3 and Digital Audio Players";
}
if($itemno<=27){
$itemtype = "Full HD TVs";
}
if($itemno<=18){
$itemtype = "Plasma TVs";
}
if($itemno<=9){
$itemtype = "LCD TVs";
}


if
($itemno >=1 && $itemno <=3 || $itemno >=10 && $itemno <=12 ||
$itemno >=19 && $itemno <=21 || $itemno >=28 && $itemno <=30 ||
$itemno >=37 && $itemno <=39 || $itemno >=46 && $itemno <=48 ||
$itemno >=55 && $itemno <=57){
$subcat = "Bestsellers";
}
elseif
($itemno >=4 && $itemno <=6 || $itemno >=13 && $itemno <=15 ||
$itemno >=22 && $itemno <=24 || $itemno >=31 && $itemno <=33 ||
$itemno >=40 && $itemno <=42 || $itemno >=49 && $itemno <=51 ||
$itemno >=58 && $itemno <=60){
$subcat = "New Releases";
}
elseif
($itemno >=7 && $itemno <=9 || $itemno >=16 && $itemno <=18 ||
$itemno >=25 && $itemno <=27 || $itemno >=34 && $itemno <=36 ||
$itemno >=43 && $itemno <=45 || $itemno >=52 && $itemno <=54 ||
$itemno >=61 && $itemno <=63){
$subcat = "Gifted";
}

$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other, lastUpdated) VALUES ('Electronics','$itemtype', '$subcat', '$title', '$photosource', '$otherinfo', '$today')";
$sql = mysql_query($insert);

$count --;
$itemno ++;
}
}
}

?>

it inserts all the entertainment and computing info but only parts of the electronics info, i have checked my task sheduler to see if it stops if it runs after a min but there is nothing like that selected?

does anyone have any ideas

p.s the electronics one works fine on its own, so should i set up several shedules to update each page individually? and only delete all records in the first task and have them run 1 min apart which may cause problems with lack of data for a couple of mins?

im a bit stuck on where to go :(

cheers

_Aerospace_Eng_
05-13-2009, 07:03 PM
You need to change your auto increment data type to something like mediumint. int by default only goes up to 127 or down to -126. It might include -127 not sure. mediumint can support up to 16 milllion.

LJackson
05-13-2009, 07:15 PM
ah ok thank you

LJackson
05-14-2009, 12:47 AM
another little problem has occured, it seems that the db table isnt being given enough time to clear all the data before the new data is inserted therefor leaving old data behind which causes problems with my pages.

any ideas how i can solve this?

should i just run a query to see if all data is gone and then proceed? or is there a better way?

thanks
Luke

_Aerospace_Eng_
05-14-2009, 06:46 AM
You could try changing this line

mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
to this

$result = mysql_query("TRUNCATE TABLE `category_data`");
Then just before you run your other queries check to see if $result is true or not.

if($result)
{
// do other queries
}
or keep what you have but as you said check to see if the table is completely empty.

$query = mysql_query("SELECT COUNT(*) FROM `category_data`") or die(mysql_error());
if(mysql_num_rows($query) == 0)
{
// do queries
}
else
{
mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
// do queries
}
You could probably do the queries after the if statement though truncate is usually instant. You could also use sleep() inside of your php. This may not be reliable as it may take longer to truncate a larger table than a smaller one.

LJackson
05-14-2009, 02:17 PM
ok thanks mate,


$emptytable = mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());

$query = mysql_query("SELECT COUNT(*) FROM `category_data`") or die(mysql_error());
print mysql_num_rows($query);
if(mysql_num_rows($query) == 0){



the above is what i have before my other queries but for some reason although the db is empty the result of the print = 1, which is odd as there are no rows in the db???

also will this method try and run until the db rows = 0 or will it check once and not run the other queries if the rows does not equal 0???

thanks

_Aerospace_Eng_
05-14-2009, 03:47 PM
It will just run once. Try this instead

$query = mysql_query("SELECT * FROM `category_data`") or die(mysql_error());

LJackson
05-14-2009, 07:06 PM
ok thats given me 0 rows which is cool....

but i still have the problem where by if the db is not empty the code wont do anything :(

should i create a function and include all the inserting data and the rows check in that function and then in the else statment have it run the function again?

any ideas
cheers mate
Luke

_Aerospace_Eng_
05-14-2009, 08:43 PM
What you could do is have a while loop. I did this on a previous project. Run a query to get the number of rows in the database. If its greater than 0 set a flag so something like this

$flag = false;
$query = mysql_query("SELECT * FROM `category_data`") or die(mysql_error());
if(mysql_num_rows($query) > 0)
{
$flag = true;
}
while($flag)
{
mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
$result = mysql_query("SELECT * FROM `category_data`") or die(mysql_error());
if(mysql_num_rows($result) == 0)
{
$flag = false;
}
}

Make you run the above just after your truncate query. That should run until the table is empty and then it will move on to process the rest of your script. Forget about what I said previously. No need to check anything. Just plop the above after your first truncate in your code how it originally was and that should work.

LJackson
05-14-2009, 08:50 PM
ok mate so would this be right?



$today = date("d-M-Y, h:i a");

$flag = false;
$query = mysql_query("SELECT * FROM `category_data`") or die(mysql_error());
if(mysql_num_rows($query) > 0)
{
$flag = true;
}
while($flag)
{
mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
$result = mysql_query("SELECT * FROM `category_data`") or die(mysql_error());
if(mysql_num_rows($result) == 0)
{
$flag = false;

//Entertainment Update
$feeds = array(
"http://www.amazon.co.uk/rss/bestsellers/dvd/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/new-releases/dvd/ref=pd_nr_rss_link","http://www.amazon.co.uk/rss/most-gifted/dvd/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/music/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/music/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/music/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/videogames/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/videogames/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/videogames/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/dvd/383380011/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/dvd/383380011/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/dvd/383380011/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/books/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/books/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/books/ref=pd_mw_rss_link"
);

$itemno = 1;
$itemtype = 0;

foreach ($feeds as $feed){
$count = 2;

$feedreader = simplexml_load_file
("$feed");
foreach ($feedreader->channel->item as $item) {
$title = addslashes ($item->title);
$photosource = get_string_between($item->description, '<img src="','"');
$otherinfo = get_string_between($item->description, '<span class="riRssContributor">','</span>');
if($count >= 0){

if($itemno<=45){
$itemtype = "Books";
}
if($itemno<=36){
$itemtype = "Blu-Ray";
}
if($itemno<=27){
$itemtype = "Video Games";
}
if($itemno<=18){
$itemtype = "CD";
}
if($itemno<=9){
$itemtype = "DVD";
}


if
($itemno >=1 && $itemno <=3 || $itemno >=10 && $itemno <=12 ||
$itemno >=19 && $itemno <=21 || $itemno >=28 && $itemno <=30 ||
$itemno >=37 && $itemno <=39){
$subcat = "Bestsellers";
}
elseif
($itemno >=4 && $itemno <=6 || $itemno >=13 && $itemno <=15 ||
$itemno >=22 && $itemno <=24 || $itemno >=31 && $itemno <=33 ||
$itemno >=40 && $itemno <=42){
$subcat = "New Releases";
}
elseif
($itemno >=7 && $itemno <=9 || $itemno >=16 && $itemno <=18 ||
$itemno >=25 && $itemno <=27 || $itemno >=34 && $itemno <=36 ||
$itemno >=43 && $itemno <=45){
$subcat = "Gifted";
}

$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other, lastUpdated) VALUES ('Entertainment','$itemtype', '$subcat', '$title', '$photosource', '$otherinfo', '$today')";
$sql = mysql_query($insert);

$count --;
$itemno ++;
}
}
}

}


thanks

_Aerospace_Eng_
05-15-2009, 01:13 AM
Does it work? That seems like it would work because it will only run those queries once the table has no rows in it. It does help if you actually TRY these things on your own.

LJackson
05-15-2009, 02:39 PM
lol hi yeah sorry i tend to write before i try

i have tried it and for some reason its still not working properly, which is very strange,

i've tried all sorts of things to try and get this to work but had no luck,

here is my code

<?php
$user_name = "";
$password = "";
$database = "";
$server = "";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);


function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());

$flag = false;
$query = mysql_query("SELECT * FROM `category_data`") or die(mysql_error());
if(mysql_num_rows($query) > 0){
$flag = true;
}

while($flag){
mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
$result = mysql_query("SELECT * FROM `category_data`") or die(mysql_error());
}

if(mysql_num_rows($result) == 0){
$today = date("d-M-Y, h:i a");

$flag = false;
//Entertainment Update
$feeds = array(
"http://www.amazon.co.uk/rss/bestsellers/dvd/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/new-releases/dvd/ref=pd_nr_rss_link","http://www.amazon.co.uk/rss/most-gifted/dvd/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/music/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/music/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/music/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/videogames/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/videogames/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/videogames/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/dvd/383380011/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/dvd/383380011/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/dvd/383380011/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/books/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/books/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/books/ref=pd_mw_rss_link"
);

$itemno = 1;
$itemtype = 0;

foreach ($feeds as $feed){
$count = 2;

$feedreader = simplexml_load_file
("$feed");
foreach ($feedreader->channel->item as $item) {
$title = addslashes ($item->title);
$photosource = get_string_between($item->description, '<img src="','"');
$otherinfo = get_string_between($item->description, '<span class="riRssContributor">','</span>');
if($count >= 0){

if($itemno<=45){
$itemtype = "Books";
}
if($itemno<=36){
$itemtype = "Blu-Ray";
}
if($itemno<=27){
$itemtype = "Video Games";
}
if($itemno<=18){
$itemtype = "CD";
}
if($itemno<=9){
$itemtype = "DVD";
}


if
($itemno >=1 && $itemno <=3 || $itemno >=10 && $itemno <=12 ||
$itemno >=19 && $itemno <=21 || $itemno >=28 && $itemno <=30 ||
$itemno >=37 && $itemno <=39){
$subcat = "Bestsellers";
}
elseif
($itemno >=4 && $itemno <=6 || $itemno >=13 && $itemno <=15 ||
$itemno >=22 && $itemno <=24 || $itemno >=31 && $itemno <=33 ||
$itemno >=40 && $itemno <=42){
$subcat = "New Releases";
}
elseif
($itemno >=7 && $itemno <=9 || $itemno >=16 && $itemno <=18 ||
$itemno >=25 && $itemno <=27 || $itemno >=34 && $itemno <=36 ||
$itemno >=43 && $itemno <=45){
$subcat = "Gifted";
}

$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other, lastUpdated) VALUES ('Entertainment','$itemtype', '$subcat', '$title', '$photosource', '$otherinfo', '$today')";
$sql = mysql_query($insert);

$count --;
$itemno ++;
}
}
}


//COMPUTING UPDATE
$feeds2 = array(
"http://www.amazon.co.uk/rss/bestsellers/electronics/14014421/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/14014421/ref=pd_nr_rss_link","http://www.amazon.co.uk/rss/most-gifted/electronics/14014421/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/electronics/14014431/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/14014431/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/electronics/14014431/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/electronics/120100031/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/120100031/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/electronics/120100031/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/10392741/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/10392741/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/10392741/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/296746011/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/561940/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/296746011/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/software/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/software/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/software/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/561904/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/561904/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/561904/ref=pd_mg_rss_link",
);

$itemno = 1;
$itemtype = 0;

foreach ($feeds2 as $feed){
$count = 2;

$feedreader = simplexml_load_file
("$feed");
foreach ($feedreader->channel->item as $item) {
$title = addslashes ($item->title);
$photosource = get_string_between($item->description, '<img src="','"');
$otherinfo = get_string_between($item->description, '<span class="riRssContributor">','</span>');
if($count >= 0){



if($itemno<=63){
$itemtype = "Accessories";
}
if($itemno<=54){
$itemtype = "Software";
}
if($itemno<=45){
$itemtype = "Scanner";
}
if($itemno<=36){
$itemtype = "Printer";
}
if($itemno<=27){
$itemtype = "Netbook";
}
if($itemno<=18){
$itemtype = "Notebook";
}
if($itemno<=9){
$itemtype = "Desktop";
}


if
($itemno >=1 && $itemno <=3 || $itemno >=10 && $itemno <=12 ||
$itemno >=19 && $itemno <=21 || $itemno >=28 && $itemno <=30 ||
$itemno >=37 && $itemno <=39 || $itemno >=46 && $itemno <=48 ||
$itemno >=55 && $itemno <=57){
$subcat = "Bestsellers";
}
elseif
($itemno >=4 && $itemno <=6 || $itemno >=13 && $itemno <=15 ||
$itemno >=22 && $itemno <=24 || $itemno >=31 && $itemno <=33 ||
$itemno >=40 && $itemno <=42 || $itemno >=49 && $itemno <=51 ||
$itemno >=58 && $itemno <=60){
$subcat = "New Releases";
}
elseif
($itemno >=7 && $itemno <=9 || $itemno >=16 && $itemno <=18 ||
$itemno >=25 && $itemno <=27 || $itemno >=34 && $itemno <=36 ||
$itemno >=43 && $itemno <=45 || $itemno >=52 && $itemno <=54 ||
$itemno >=61 && $itemno <=63){
$subcat = "Gifted";
}

$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other, lastUpdated) VALUES ('Computing','$itemtype', '$subcat', '$title', '$photosource', '$otherinfo', '$today')";
$sql = mysql_query($insert);

$count --;
$itemno ++;
}
}
}

//Electronics Update

$feeds3 = array(
"http://www.amazon.co.uk/rss/bestsellers/electronics/14210121/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/14210121/ref=pd_nr_rss_link","http://www.amazon.co.uk/rss/most-gifted/electronics/14210121/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/electronics/1062130/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/1062130/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/electronics/1062130/ref=pd_mg_rss_link", "http://www.amazon.co.uk/rss/bestsellers/electronics/492731011/ref=pd_ts_rss_link", "http://www.amazon.co.uk/rss/new-releases/electronics/492731011/ref=pd_nr_rss_link", "http://www.amazon.co.uk/rss/most-gifted/electronics/492731011/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/573372/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/573372/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/573372/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/560836/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/560836/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/560836/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/4085991/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/4085991/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/4085991/ref=pd_mg_rss_link",
"http://www.amazon.co.uk/rss/bestsellers/electronics/560860/ref=pd_ts_rss_link",
"http://www.amazon.co.uk/rss/new-releases/electronics/560860/ref=pd_nr_rss_link",
"http://www.amazon.co.uk/rss/most-gifted/electronics/560860/ref=pd_mg_rss_link",
);

$itemno = 1;
$itemtype = 0;

foreach ($feeds3 as $feed){
$count = 2;

$feedreader = simplexml_load_file
("$feed");
foreach ($feedreader->channel->item as $item) {
$title = addslashes ($item->title);
$photosource = get_string_between($item->description, '<img src="','"');
$otherinfo = get_string_between($item->description, '<span class="riRssContributor">','</span>');
if($count >= 0){

if($itemno<=63){
$itemtype = "DVD Players";
}
if($itemno<=54){
$itemtype = "Home Cinema Systems";
}
if($itemno<=45){
$itemtype = "Digital Cameras";
}
if($itemno<=36){
$itemtype = "MP3 and Digital Audio Players";
}
if($itemno<=27){
$itemtype = "Full HD TVs";
}
if($itemno<=18){
$itemtype = "Plasma TVs";
}
if($itemno<=9){
$itemtype = "LCD TVs";
}

if
($itemno >=1 && $itemno <=3 || $itemno >=10 && $itemno <=12 ||
$itemno >=19 && $itemno <=21 || $itemno >=28 && $itemno <=30 ||
$itemno >=37 && $itemno <=39 || $itemno >=46 && $itemno <=48 ||
$itemno >=55 && $itemno <=57){
$subcat = "Bestsellers";
}
elseif
($itemno >=4 && $itemno <=6 || $itemno >=13 && $itemno <=15 ||
$itemno >=22 && $itemno <=24 || $itemno >=31 && $itemno <=33 ||
$itemno >=40 && $itemno <=42 || $itemno >=49 && $itemno <=51 ||
$itemno >=58 && $itemno <=60){
$subcat = "New Releases";
}
elseif
($itemno >=7 && $itemno <=9 || $itemno >=16 && $itemno <=18 ||
$itemno >=25 && $itemno <=27 || $itemno >=34 && $itemno <=36 ||
$itemno >=43 && $itemno <=45 || $itemno >=52 && $itemno <=54 ||
$itemno >=61 && $itemno <=63){
$subcat = "Gifted";
}

$insert = "INSERT INTO category_data (page_category, cat_id, subcat_id, title, image, other, lastUpdated) VALUES ('Electronics','$itemtype', '$subcat', '$title', '$photosource', '$otherinfo', '$today')";
$sql = mysql_query($insert);

$count --;
$itemno ++;
}
}
}

}
?>

are there any obvious errors in there that i have missed?

thanks for your time
Luke

_Aerospace_Eng_
05-15-2009, 03:28 PM
You changed to code to where now its an endless loop. Put EXACTLY what I gave you after this line

mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
rollback the changes you've made. Don't change anything.

LJackson
05-15-2009, 04:02 PM
ahhh lol sorry!!! me and loops dont go :(

ok here is what i have without any of my inserting code

mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());


$flag = false;
$query = mysql_query("SELECT * FROM `category_data`") or die(mysql_error());
if(mysql_num_rows($query) <> 0){
$flag = true;
}

while($flag){

mysql_query("TRUNCATE TABLE `category_data`") or die(mysql_error());
$result = mysql_query("SELECT * FROM `category_data`") or die(mysql_error());
if(mysql_num_rows($result) == 0){
$flag = false;
}
}

where should i put my code? should i do another if statment to check flag is false and then insert my code there or should i insert it after this line $flag = false;?

thanks
Luke

_Aerospace_Eng_
05-15-2009, 04:30 PM
No now put your code after that. Your code will only run if the table is empty. That loop will keep going until the table is empty. And this

if(mysql_num_rows($query) <> 0){
$flag = true;
}
should be

if(mysql_num_rows($query) > 0){
$flag = true;
}

LJackson
05-15-2009, 04:33 PM
cool, just ran it and it seems to work for the moment lol, i will wait until it runs for it self via the task sheduler see if it is all ok :)

thanks again for your help
Luke

LJackson
05-15-2009, 04:50 PM
strange... for some reason if i run it by going to the url it works fine and there are the correct number of rows, but if it does it via the task sheduler it all goes tits up, even thought its the same file being run

i wonder if i remove those statments from the actions tab of the task sheduler(-q -O nul)? thats the only thing i can think of?

_Aerospace_Eng_
05-15-2009, 04:54 PM
You can try. I can't remember if I asked you before but who is your webhost? You could look into this

http://www.onlinecronjobs.com/

I just tried it and it seems to do the job fine. Will beat having to have your computer on too.

I've had trouble with cron jobs running successfully on my server. This seems to be a decent alternative.

LJackson
05-15-2009, 05:04 PM
thanks i will look into this :)

my host is one.com

thank you.

i will report back later to let you know how i get on

Luke

LJackson
05-19-2009, 12:39 PM
hi aerospace_eng,

i have re-coded my page and everything seems to run fine now, (fingers crossed :) )

thanks for all your help, really appreciate it

Luke

Philip M
05-19-2009, 01:04 PM
ok just contacted my host and they said CRON is not supported :(
so i assume its a windows based server.

i also asked if i could use the task sheduler to perform the task and was told "well if it does not require cron then it is fine"

I think that "not supported" really means "not permitted". Quite a few ISPs do not permit CRON jobs, perhaps fearing excessive usage.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum