<?php

// new 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.");
/*
$connection=mysql_connect('localhost', 'root', '1234') or die ("Verbindungsversuch fehlgeschlagen");
mysql_select_db('topreef', $connection) or die("Konnte die Datenbank nicht waehlen.");
*/
echo "get items";
$query = mysql_query('select i.id, i.name, i.inventory, iin.id iiid from items  i left join item_inventory iin on i.id = iin.item_id') or die("Anfrage nicht erfolgreich");
$data = array();
while($obj = mysql_fetch_object($query)) {
	$item_ids[] = $obj;
}


echo "set structures";
foreach ($item_ids as $obj) {
	if ($obj->iiid == NULL) {
		$sql = "
			UPDATE items
			SET inventory=0
			WHERE id=".$obj->id;

		echo $sql;echo "<br />";
		$query = mysql_query($sql);
	}
}
echo "ende";

/*
echo "get items<br>";
$sql = "SELECT id, parent_id FROM items";
$query = mysql_query($sql);
$item_ids = array();
$parent_ids = array();
while($obj = mysql_fetch_object($query)) {
	$manufacturers[$obj->name] = $obj->id;
	$item_ids[] = $obj->id;
	$parent_ids['p'.$obj->parent_id] = 1;
}

echo "update items<br>";
foreach ($item_ids as $item_id) {
	if (!isset($parent_ids['p'.$item_id])) {
		$sql = "
			UPDATE items
			SET schema_id=0
			WHERE id=".$item_id.' AND parent_id = 0';

		echo $sql;echo "<br />";
		$query = mysql_query($sql);
	}

}
*/




?>