マジックザギャザリングカードの在庫システムを作成していますが、メインのカード情報で価格を更新する必要があります。
カードと価格の2つのテーブルがあります
カードには次の列があります:ID、名前、エド、価格
価格には次の列があります:名前、エド、価格
Cards.PriceをPrices.Priceの値に置き換える必要があります。
以下は、これを機能させるための2つの異なる試みのコードです(私はおそらくこれを必要以上に難しくしていることを知っています...)
試行#1
$query = "SELECT * FROM Cards";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$name=$row['Name'];
$ed=$row['Ed'];
$queryb = "SELECT Price FROM Prices WHERE Name='".$name."' AND Ed='".$ed."'";
$resultb = mysql_query($queryb) or die(mysql_error());
$rowb = mysql_fetch_array($resultb) or die(mysql_error());
$newPrice = $rowb['Price'];
mysql_query("UPDATE Cards SET Price='".$newPrice."'");
}
試行#2
$queryCards = "SELECT * FROM Cards";
$queryPrices = "SELECT * FROM Prices";
$dblink = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $dblink);
$resultCards = mysql_query($queryCards) or die(mysql_error());
$resultPrices = mysql_query($queryPrices) or die(mysql_error());
$rowCards = mysql_fetch_array($resultCards) or die(mysql_error());
$rowPrices = mysql_fetch_array($resultPrices) or die(mysql_error());
if ($rowCards['Name']==$rowPrices['Name'] && $rowCards['Ed']==$rowPrices['Ed'])
{
$newPrice = $rowPrices['Price'];
mysql_query("UPDATE Cards SET Price='".$newPrice."' WHERE
Name='".$rowCards['Name']."' AND Ed='".$rowCards['Ed']."'");
}
while($rowPrices = mysql_fetch_array($resultPrices))
{
if ($rowCards['Name']==$rowPrices['Name'] &&
$rowCards['Ed']==$rowPrices['Ed'])
{
$newPrice = $rowPrices['Price'];
mysql_query("UPDATE Cards SET Price='".$newPrice."' WHERE
Name='".$rowCards['Name']."' AND Ed='".$rowCards['Ed']."'");
}
}
$rowPrices = mysql_fetch_array($resultPrices) or die(mysql_error());
while($rowCards = mysql_fetch_array($resultCards))
{
while($rowPrices = mysql_fetch_array($resultPrices))
{
if ($rowCards['Name']==$rowPrices['Name'] &&
$rowCards['Ed']==$rowPrices['Ed'])
{
$newPrice = $rowPrices['Price'];
mysql_query("UPDATE Cards SET Price='".$newPrice."' WHERE
Name='".$rowCards['Name']."' AND Ed='".$rowCards['Ed']."'");
}
}
}