Xtremer360 Posted February 1, 2011 Share Posted February 1, 2011 I accidently posted this in the PHP applications board and didn't mean to because its a blizzard here and my comp is getting slow and lagging and I thought I had clicked in the right board but I was wrong so if a mod, admin can delete that other entry I'd be thankful. I'm trying to queries together because I have this query but I want to only put in those characters that have not been taken so I have another table that lists all the characters that are used. TABLE handler_characters which has fields called id, handler_id, character_id. What I want to somehow do is have it get all the character_ids out of that table and then subtract those ids from this query so it won't list them as options. Any thoughts on how to accomplish this? <?php $query = 'SELECT id, charactername FROM characters ORDER BY `charactername`'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['charactername']."</option>\r"; } ?> Link to comment https://forums.phpfreaks.com/topic/226402-subtracting-options-with-one-table-to-another/ Share on other sites More sharing options...
AbraCadaver Posted February 1, 2011 Share Posted February 1, 2011 More of a MySQL question but try: $query = 'SELECT characters.id, characters.charactername FROM characters, handler_characters WHERE characters.id != handler_characters.character_id ORDER BY characters.charactername'; Link to comment https://forums.phpfreaks.com/topic/226402-subtracting-options-with-one-table-to-another/#findComment-1168579 Share on other sites More sharing options...
Xtremer360 Posted February 2, 2011 Author Share Posted February 2, 2011 That didn't work however this did. <?php $query = 'SELECT id, charactername FROM characters WHERE id NOT IN (SELECT character_id FROM handler_characters) ORDER BY `charactername`'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['charactername']."</option>\r"; } ?> Link to comment https://forums.phpfreaks.com/topic/226402-subtracting-options-with-one-table-to-another/#findComment-1168625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.