• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:


Im using the following function to pull records for a dropdown. The dropdown is working however the results are not what I am looking for.

I cant get the NOT IN to work below its just displaying all the records in "$strTableName " and not removing the matching field "onetimeID" in the picksummary table..

Any advice would be greatfull.


function OneTimedropdown($intIdField, $strNameField, $strTableName, $strNameOrdinal, $strOrderField, $userID, $strMethod="asc") {
   echo "<select name=\"$strNameOrdinal\">\n";
   echo "<option value=\"NULL\">".$strMaskName."</option>\n";
   $strQuery = "select $intIdField, $strNameField
            from $strTableName
                 WHERE $strNameField NOT IN (select onetimeID FROM nflp_picksummary where userID = '" . $user->userID . "')";
   $rsrcResult = mysql_query($strQuery);

   while($arrayRow = mysql_fetch_assoc($rsrcResult)) {
      $strA = $arrayRow["$intIdField"];
      $strB = $arrayRow["$strNameField"];
      echo "<option value=\"$strA\">$strB</option>\n";

   echo "</select>";
3 Solutions
Julian HansenCommented:
What does the query expand to - if you put an

echo $strQuery;

After the assignment - what do you get.

The $strNameField - needs to be a value that can be linked to your onetimeID

The inner query is finding all records from nflp_picksummary where the userID matches your $userID value. The outer query is then going to look for all values of the field $strNameField that don't match this value.

If your $strNameField - is a list of team names and onetimeID is a numeric identifier then it will always return the full recordset because a name

"Bob Smit"

Is never going to be equal to an id (291 say)

You need to be matching apples with apples
Chris StanyonCommented:
You seem to have a number of mismatching Variables.

echo "<option value=\"NULL\">".$strMaskName."</option>\n";
No $strMaskName defined or passed!!

where userID = '" . $user->userID . "')";
You pass in userID to the function, not $user

You should no longer be using mysql_* functions. They're deprecated. You need to switch to PDO or mySQLi.
Ray PaseurCommented:
This will help with the switch to PDO or MySQLi.

Whenever I have something that is too complicated to understand readily, I try to deconstruct the problem into something I can understand, and get that part correct, then build the application up from a verified foundation.  This practice is kind of at the confluence of test-driven development and SSCCE.  In the instant case, I think I would go to work on the sub-query:

... select onetimeID FROM nflp_picksummary where userID = '" . $user->userID . "'

Once you know that part gives you a good result, then you can add it back into the larger query NOT IN clause.  But don't try to eat the elephant all at once -- a bite at a time will be enough.

Along the way, you will probably learn that var_dump() is your friend.  In PHP it's all about the data (we are not driving robot surgery machines or flying spacecraft) and so it follows that good visualization of the data is what's most important for PHP programmers at all levels.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

MPDenverAuthor Commented:
I've requested that this question be deleted for the following reason:

I received recommendations and no solutions to my question.
Julian HansenCommented:
I received recommendations and no solutions to my question.

You have not responded to questions posed by experts regarding this issue. If you want a solution - please respond so that we can find a solution
MPDenverAuthor Commented:
Thanks for everyone's comments
MPDenverAuthor Commented:
I was not intending to be rude or unprofessional.  I resolved the issue in an other manner and felt closing the forum was appropriate.  Everyone got their points now so be happy.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now