Script doesn't work if put into a loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ankhmor
Forum Newbie
Posts: 12
Joined: Fri Jul 13, 2007 4:45 pm

Script doesn't work if put into a loop

Post by ankhmor »

the script below works perfectly. However I want it to run forever in bash (Linux Terminal) and as far as I see it the only way to do that is to enclose the whole script in a loop.
When I enclose below script in a loop (

Code: Select all

like while (1 == 1){}
) it doesn't work properly anymore.

Code: Select all

mysql_connect("localhost", "root", "new-password") or die("Couldnt connect");
mysql_select_db("profiles") or die("Couldnt select");
	echo "excecuting ...";
	$array = file("http://oh2aq.kolumbus.com/dxs/dx250.html?");
$last = mysql_query("SELECT `id`, `call` FROM `list` ORDER BY id DESC LIMIT 1") or die(mysql_error()."\nline 8");
$a = 1;
$count = count($array) - 2;
$test = mysql_result($last, 0, 'call');
while($test != $info[0]){
$info = preg_split("/ /", $array[$a], -1, PREG_SPLIT_NO_EMPTY);
	$a++;
}
$b = 0;
$a = $a - 2;
	while($a > $b ){
			$info_2 = preg_split("/ /", $array[$a], -1, PREG_SPLIT_NO_EMPTY);
			$comments = explode ("\n", chunk_split($array[$a], 30, "\n"));
			$comment = str_replace("'", '"', $comments[1]);
echo $info_2[0]."|--|".$info_2[1]."|--|".$info_2[2]."|--|".$comment."|--|".$a."\n";
mysql_query("INSERT INTO `list` (`call`, `frequency`, `other_call`, `comments`) VALUES ('$info_2[0]', '$info_2[1]', '$info_2[2]', '$comment')") or die(mysql_error()."\nline 25");
$a--;
	}
	mysql_close();
Oh almost forgot. The main function of the script is to get new entries from a website and to store them in mysql database.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Yo might be interested in cron jobs
ocpamit
Forum Newbie
Posts: 7
Joined: Fri Jul 13, 2007 6:53 am
Location: Punjab, India

Post by ocpamit »

yeah cron job is the right solution.
ankhmor
Forum Newbie
Posts: 12
Joined: Fri Jul 13, 2007 4:45 pm

Post by ankhmor »

thanks guys
Post Reply