Far Cry Posted June 25, 2011 Share Posted June 25, 2011 <?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. Link to comment https://forums.phpfreaks.com/topic/240383-how-do-i-select-data-from-different-tables/ Share on other sites More sharing options...
Eiolon Posted June 25, 2011 Share Posted June 25, 2011 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. Link to comment https://forums.phpfreaks.com/topic/240383-how-do-i-select-data-from-different-tables/#findComment-1234749 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.