nerdpowah23
New Member
- Messages
- 14
- Reaction score
- 0
- Points
- 0
Here are the tables.
-- Table structure for table `items`
--
CREATE TABLE IF NOT EXISTS `items` (
`item_id` bigint(20) NOT NULL auto_increment,
`item_name` varchar(255) NOT NULL,
`item_description` text NOT NULL,
`item_type` varchar(25) NOT NULL,
`item_cost` double NOT NULL,
`item_sell_value` double NOT NULL,
PRIMARY KEY (`item_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`userid` bigint(20) NOT NULL auto_increment,
`username` varchar(50) NOT NULL,
`password` varchar(255) NOT NULL,
`email` varchar(75) NOT NULL,
`userlevel` varchar(50) NOT NULL,
`register_date` datetime NOT NULL,
`last_login` datetime NOT NULL,
`total_logins` bigint(20) NOT NULL,
`ip` varchar(50) NOT NULL,
`locked` tinyint(1) NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
-- Table structure for table `user_equipped_items`
--
CREATE TABLE IF NOT EXISTS `user_equipped_items` (
`userid` bigint(20) NOT NULL,
`primary_id` bigint(20) NOT NULL default '0',
`secondary_id` bigint(20) NOT NULL default '0',
`melee_id` bigint(20) NOT NULL default '0',
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `user_items`
--
CREATE TABLE IF NOT EXISTS `user_items` (
`userid` bigint(20) NOT NULL,
`item_id` bigint(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
My question is, how do I join the user_equipped_items table into the query so I can exclude all items that the user currently has equipped from the while loop?
-- Table structure for table `items`
--
CREATE TABLE IF NOT EXISTS `items` (
`item_id` bigint(20) NOT NULL auto_increment,
`item_name` varchar(255) NOT NULL,
`item_description` text NOT NULL,
`item_type` varchar(25) NOT NULL,
`item_cost` double NOT NULL,
`item_sell_value` double NOT NULL,
PRIMARY KEY (`item_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`userid` bigint(20) NOT NULL auto_increment,
`username` varchar(50) NOT NULL,
`password` varchar(255) NOT NULL,
`email` varchar(75) NOT NULL,
`userlevel` varchar(50) NOT NULL,
`register_date` datetime NOT NULL,
`last_login` datetime NOT NULL,
`total_logins` bigint(20) NOT NULL,
`ip` varchar(50) NOT NULL,
`locked` tinyint(1) NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
-- Table structure for table `user_equipped_items`
--
CREATE TABLE IF NOT EXISTS `user_equipped_items` (
`userid` bigint(20) NOT NULL,
`primary_id` bigint(20) NOT NULL default '0',
`secondary_id` bigint(20) NOT NULL default '0',
`melee_id` bigint(20) NOT NULL default '0',
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `user_items`
--
CREATE TABLE IF NOT EXISTS `user_items` (
`userid` bigint(20) NOT NULL,
`item_id` bigint(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
PHP:
<?php
$query = mysql_query("SELECT * FROM items LEFT JOIN user_items ON
items.item_id=user_items.item_id WHERE user_items.userid='$userid'");
$numrows = mysql_num_rows($query);
if($numrows > 0){
while($row = mysql_fetch_assoc($query)){
$name = $row['item_name'];
$id= $row['item_id'];
$type = $row['item_type'];
$cost = $row['item_cost'];
$sell_value = $row['item_sell_value'];
?>
<tr>
<td><?php echo"$name";?></td>
<td><?php echo"$type";?></td>
<td><?php echo money_format('%(#10n', $cost);?></td>
<td><?php echo money_format('%(#10n', $sell_value);?></td>
Last edited: