PHP SQL LOOKUP

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.

Thanks

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>";
}
MPDenverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris StanyonWebDevCommented:
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.
0
Ray PaseurCommented:
This will help with the switch to PDO or MySQLi.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

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.
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

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

I received recommendations and no solutions to my question.
0
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
0
MPDenverAuthor Commented:
Thanks for everyone's comments
0
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.