Question:
Trying to figure out how to use 2 operands in a MYSQL PHP query... can anyone help me...?
retlav
2010-07-21 02:04:15 UTC
Trying to figure out how to use 2 operands in a MYSQL PHP query... can anyone help me...

This is the query that i have now and i want use 2 operators on the IN statement. can any one tell me what i am doing wrong...
$get_catalog_sql_p = "SELECT * FROM instructionalprograms where major_code IN (SELECT major_code FROM mycatalogtrack_p WHERE session_id = '".$_COOKIE["PHPSESSID"]."' ORDER BY date_added)";

Using 2 operands in a join query (this is the one that's not working...

$get_catalog_sql_p = "SELECT * FROM instructionalprograms where major_code, year IN (SELECT major_code, year FROM mycatalogtrack_p WHERE session_id = '".$_COOKIE["PHPSESSID"]."' ORDER BY date_added)";
Three answers:
Joseph K
2010-07-22 10:56:10 UTC
You would need to do a second subselect for the second parameter. But why not use a join?



$get_catalog_sql_p = "SELECT ip.* FROM instructionalprograms ip

JOIN mycatalogtrack_p mct ON (

ip.major_code = mct.major_code AND

ip.year = mct.year

)

WHERE mct.session_id = '{$_COOKIE['PHPSESSID']}'

ORDER BY mct.date_added

";



And make sure you're sanitizing $_COOKIE['PHPSESSID'] if you're going to use it like that.
aftab
2010-07-21 02:14:55 UTC
Did you tried the braces.. as under



$get_catalog_sql_p = "SELECT * FROM instructionalprograms where (major_code, year) IN (SELECT major_code, year FROM mycatalogtrack_p WHERE session_id = '".$_COOKIE["PHPSESSID"]."' ORDER BY date_added)";



If its an AND kind of situation just concate the two.. ;)



$get_catalog_sql_p = "SELECT * FROM instructionalprograms where Concat(major_code, year) IN (SELECT concat(major_code, year) FROM mycatalogtrack_p WHERE session_id = '".$_COOKIE["PHPSESSID"]."' ORDER BY date_added)";



That should work :)
alim
2016-10-29 08:57:06 UTC
i can't see all your source code, yet i will provide it a attempt.... a million. the 1st element i might do is to get the entire style of archives you have in the database. you're able to try this via calling a query some thing like: 'opt for count huge style([your_primary_field]) as numrecs from tutorials' ... $numofrecs = $row['numrecs']; 2. determine on what share archives you want to instruct on a internet site. so in case you 'numrecs' is 31, and you like 10 in line with internet site, you'll want say 4 pages. surprising? $recperpage = 10; $numberofpages = ceil ($numofrecs/$recperpage); 3. you need to get yet another huge style that's the beginning factor the place you want to commence counting the subsequent '$recperpage' archives. the style you will artwork that out is via.. $starting_record = ($current_page_num* $recperpage)+a million; so while you're on internet site 3, you have finished (3*10)+a million archives, for this reason your starting_record is thirty first record. 4. you are able to then alter your opt for assertion to apply shrink assets.... opt for * FROM tutorials the place subcat = '$sub' and status='2' shrink $starting_record, $recperpage; wish that gets you all started. it isn't the cleanest of codes, whether it is going to do.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...