0
標題有點特定但最好我可以在一行中解釋。如何從一個表中提取數據並將其插入另一個表中的列?
我的問題是基本上,我有我的數據庫中的表,我查詢;
<?php
include 'connect.php';
$query = mysql_query("SELECT * FROM mobs WHERE zone='Darnolth' ORDER BY lvl ") or die(mysql_error());;
echo "<table border='1' cellpadding='2' cellspacing='0' width=800 id='mob' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Mob Name</th> <th>Level</th> <th>Health</th> <th>Drops</th> <th>Effects</th> <th>Zone</th></tr></thead><tbody>";
while($row = mysql_fetch_array($query)) {
echo "<tr><td>";
echo $row['image'];
echo "</td><td width=200>";
echo $row['mobname'];
echo "</td><td width=50>";
echo $row['lvl'];
echo "</td><td width=50>";
echo $row['health'];
echo "</td><td width=200>";
echo $row['drops'];
echo "</td><td width=100>";
echo $row['effects'];
echo "</td><td width=75>";
echo $row['zone'];
echo "</td></tr>";
}
echo "</tbody></table>";
?>
現在這一切都是好的,但滴行需要拉其通過從項目表暴徒在我的分貝放棄了所有項目的圖像
所以就需要在電話會議上商品表中的名稱與上述查詢中的生物名稱相同的行中的圖像。
我試着添加另一個查詢內但沒有做任何事情,我不能想到別的。
謝謝。
試圖用INNER JOIN來修改我的代碼;
<?php
include 'connect.php';
$query = mysql_query("SELECT mobs.image, mobs.mobname, mobs.lvl, mobs.health, mobs.drops, mobs.effects, mobs.zone, misc.droppedby FROM mobs JOIN misc ON mobs.drops = misc.droppedby") or die(mysql_error());;
echo "<table border='1' cellpadding='2' cellspacing='0' width=800 id='mob' class='tablesorter'><thead>";
echo "<tr> <th> </th> <th>Mob Name</th> <th>Level</th> <th>Health</th> <th>Drops</th> <th>Effects</th> <th>Zone</th></tr></thead><tbody>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($query)) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['image'];
echo "</td><td width=200>";
echo $row['mobname'];
echo "</td><td width=50>";
echo $row['lvl'];
echo "</td><td width=50>";
echo $row['health'];
echo "</td><td width=200>";
echo $row['drops'];
echo "</td><td width=100>";
echo $row['effects'];
echo "</td><td width=75>";
echo $row['zone'];
echo "</td></tr>";
}
echo "</tbody></table>";
?>
,但現在這只是導致我的小怪表按我的其它表的項目數量加載每個暴民,所以我有mob1 100倍和MOB2 100倍液等,但它不拉圖像從misc表中放到怪物表的drop列中。
感謝您的快速回復,試了一下,見上面,想我失去了一些東西 – Rath 2011-01-25 20:16:12