Jump to content

How do I select data from different tables?


Far Cry

Recommended Posts

<?php require("styles/top.php"); ?>

<?php
if(isLoggedin($valid)){
?>
<center><h1>Your Items</h1></center>
<?php
$query = mysql_query("SELECT * FROM farcry_crime_town.user_items WHERE userid='$userid'");
$numrows = mysql_num_rows($query);
if($numrows > 0){
while($row = mysql_fetch_assoc($query)){

  } else {
echo"An error has occured, please refresh this page.";
  }
} else {
echo"You have no items.";
}

?>


<?php
} else {
?>


<?php
}
?>

So I have a user_items table that has:

userid (So it keeps track of who has the item)

the item_id

and the item_name

 

However, I also have an items table that has:

item_id

item_name

item_description

item_type

item_desc

item_cost

item_sell_value

 

I want to grab the item_type row from the item table by comparing the item_name from the two tables and have them be in one result set. How can I acheive this? Thanks.

You need to use a join if you want to select from multiple tables in a single query.  Just compare the item ID's from both tables.

 

http://phpweby.com/tutorials/mysql/32

 

Also, no need to put the item_name column in user_items because it is already in the items table.  You can grab the name from the items table when you write your query.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.