ginerjm Posted April 26, 2023 Share Posted April 26, 2023 That is not the code that I posted for you to try out. Quote Link to comment https://forums.phpfreaks.com/topic/316209-php-help-needed/page/2/#findComment-1607740 Share on other sites More sharing options...
ginerjm Posted April 26, 2023 Share Posted April 26, 2023 I think that quitting would be a good choice. People are trying to help you but you are reading anything correctly. Quote Link to comment https://forums.phpfreaks.com/topic/316209-php-help-needed/page/2/#findComment-1607741 Share on other sites More sharing options...
Dealmightyera Posted April 26, 2023 Author Share Posted April 26, 2023 I'm just new to PHP/Mysql and don't think I can go far beyond this level... I'm still learning. Quote Link to comment https://forums.phpfreaks.com/topic/316209-php-help-needed/page/2/#findComment-1607742 Share on other sites More sharing options...
Dealmightyera Posted April 26, 2023 Author Share Posted April 26, 2023 Thanks @ginerjm It's going thru but how will i set a return when the code has already been used and when it has not been used but exist on the oda table Quote Link to comment https://forums.phpfreaks.com/topic/316209-php-help-needed/page/2/#findComment-1607746 Share on other sites More sharing options...
Barand Posted April 26, 2023 Share Posted April 26, 2023 I would use a single query which checks if the code is used in one table or the other, or both. Test data TABLE: tsc TABLE: candidates +----+-----------------+ +---------+-------+--------+ | id | transactioncode | | regcode | name | last | +----+-----------------+ +---------+-------+--------+ | 10 | 1 | | 2 | Alma | Geddon | | 11 | 2 | | 4 | Scott | Chegg | | 12 | 3 | | 5 | Sarah | Tonin | | 13 | 4 | +---------+-------+--------+ +----+-----------------+ The query and results mysql> SELECT a.transactioncode as tsc -> , coalesce(b.regcode, 'NO') as candidates -> FROM tsc a -> LEFT JOIN -> candidates b ON a.transactioncode = b.regcode -> UNION -> SELECT coalesce(a.transactioncode, 'NO') as tsc -> , b.regcode as candidates -> FROM candidates b -> LEFT JOIN -> tsc a ON a.transactioncode = b.regcode; +------+------------+ | TSC | CANDIDATES | +------+------------+ | 1 | NO | | 2 | 2 | | 3 | NO | | 4 | 4 | | NO | 5 | +------+------------+ Because you are interested in one code at a time, just add WHERE clauses to each half of the UNION. I.E.... SELECT a.transactioncode as TSC , coalesce(b.regcode, 'NO') as CANDIDATES FROM tsc a LEFT JOIN candidates b ON a.transactioncode = b.regcode WHERE transactioncode = ? UNION SELECT coalesce(a.transactioncode, 'NO') as TSC , b.regcode as CANDIDATES FROM candidates b LEFT JOIN tsc a ON a.transactioncode = b.regcode; WHERE regcode = ? Note that the the inputted code is used twice, so your execute command would be $stmt->execute( [ $code, $code ] ); Quote Link to comment https://forums.phpfreaks.com/topic/316209-php-help-needed/page/2/#findComment-1607749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.