Jump to content

Query to get item not assigned to a user


HDFilmMaker2112

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.