php - How do i pull data from one table and insert it into a column in another table? -


the title little under specific best explain in 1 line.

my problem basically, have table in db query with;

 <?php include 'connect.php';   $query = mysql_query("select * mobs zone='darnolth' order 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>";  ?> 

now fine, drops row needs pull images of items dropped mob items table in db

so need call on items table images rows have dropped name same mob name above query.

i tried adding query within did nothing, cant think of else.

thanks.

tried mod code using inner join to;

 <?php include 'connect.php';   $query =  mysql_query("select mobs.image, mobs.mobname, mobs.lvl, mobs.health, mobs.drops, mobs.effects, mobs.zone, misc.droppedby 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 next row until there no more  while($row = mysql_fetch_array( $query )) {      // print out contents of each row 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>";  ?> 

but causing mobs table load each mob amount of items in misc table, have mob1 100 times , mob2 100 times , on, doesnt pull images misc table , put them in drops column in mobs table.

what need called join. allows pull data multiple tables in single sql select query.

for example, authors each book, might do

select *  book inner join author on book.authorid = author.id 

more information on joins: http://www.w3schools.com/sql/sql_join.asp


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -