<?php

//ini_set("memory_limit","1024M");
//set_time_limit(60000);


// database
$connection=mysql_connect('localhost', 'shop_topreef_de', 'b-7+ZgQn$!') or die ("Verbindungsversuch fehlgeschlagen");
mysql_select_db('shop_topreef_de', $connection) or die("Konnte die Datenbank nicht waehlen.");

$sql = "
SELECT items.id, items.parent_id, items.number, item_files.file_name as imagetable, items.default_image_file_name as childdefault, i2.default_image_file_name as parent_default
FROM items
LEFT JOIN item_files ON item_files.item_id=items.id
LEFT JOIN items i2 ON i2.id = items.parent_id
WHERE items.parent_id != 0 AND (
item_files.type=0 OR item_files.id IS NULL
)
AND item_files.file_name IS NULL
GROUP BY items.id
";
$query = mysql_query($sql) or die("Anfrage nicht erfolgreich");
$data = array();
while($obj = mysql_fetch_object($query)) {
	$sql = "
		UPDATE items
		SET
			default_image_file_name='".$obj->parent_default."'
		WHERE id=".$obj->id."
	";
	echo "<br>".$sql;
	mysql_query($sql);
}


?>