HDFilmMaker2112 Posted July 17, 2011 Share Posted July 17, 2011 I'm trying to write a query to get an item not assigned to user. Would this be anywhere near close: SELECT $tbl_name4.item_id FROM $tbl_name4 JOIN $tbl_name2 ON ($tbl_name2.credit=$tbl_name4.position AND $tbl_name2.film_number=$tbl_name4.film_number) WHERE $tbl_name4.item_id IS NULL; My table structure is as such: $tbl_name4="credits_listing"; id | cost | position | item_id | quantity | film_number $tbl_name2="donors_credits"; id | credit | film_number | donor_id The only issue I can see with the query I have above is how to I select the specific user to choose the data from? I do have donor_id value available from a previous query. Should I add this value as a second WHERE condition? Link to comment https://forums.phpfreaks.com/topic/242165-query-to-get-item-not-assigned-to-a-user/ Share on other sites More sharing options...
HDFilmMaker2112 Posted July 17, 2011 Author Share Posted July 17, 2011 Updated Query/PHP: I know this isn't the php forum, but I'm including my php so I can show what the query results will be used for. $tbl_name has donor_id and username $tbl_name2 has item_id and donor_id $tbl_name4 has item_id and the item details <?php session_start(); $myusername=$_SESSION['myusername2']; $mypassword=$_SESSION['mypassword2']; require_once 'db_select.php'; $credit=$_GET['credit']; $credit=explode('-',$credit); $credit2=$credit[0]; $id=$_GET['id']; $sql_films=" SELECT $tbl_name4.position,$tbl_name4.film_number FROM $tbl_name4 LEFT JOIN $tbl_name2 ON $tbl_name4.item_id=$tbl_name2.item_id LEFT JOIN $tbl_name ON $tbl_name.donor_id=$tbl_name2.donor_id AND $tbl_name.donor_id='$id' WHERE $tbl_name4.item_id IS NULL"; $result_films=mysql_query($sql_films) or die(mysql_error()); $select.='<select name="new_credit">'."\n"; $select.='<option value="">Select Credit</option>'."\n"; while($row_films=mysql_fetch_array($result_films)){ extract($row_films); $select.='<option value="'.$position.'-'.$film_number.'" >'.ucwords($position).' - Film # '.$film_number.'</option>'."\n"; } $select.='</select> '; echo $select; ?> Link to comment https://forums.phpfreaks.com/topic/242165-query-to-get-item-not-assigned-to-a-user/#findComment-1243679 Share on other sites More sharing options...
fenway Posted July 17, 2011 Share Posted July 17, 2011 Please post the raw query -- by echo()-ing it -- without PHP variables. Link to comment https://forums.phpfreaks.com/topic/242165-query-to-get-item-not-assigned-to-a-user/#findComment-1243844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.