Barand Posted May 20, 2007 Share Posted May 20, 2007 Define "doesn't work". What are the values in the search variables when it "doesn't work"? Quote Link to comment https://forums.phpfreaks.com/topic/49668-sql-conversion/page/3/#findComment-257502 Share on other sites More sharing options...
maliary Posted May 20, 2007 Author Share Posted May 20, 2007 Sorry for being so vague. Well, what i mean is when i try searching using either the last name, first name or pid with the date range it doesn't give any results, when it actually should be. Searching using a number with the date range -- for the encounter_nr -- produces the correct search results. Here is the form that does the search,if it helps <FORM action="<?php echo $thisfile; ?>" method="post" name="sform" onSubmit="return checkForm(sform.keyword)"> <B><?php echo 'Enter Date Range' ?></B></font><p> From:<font size=3> <INPUT READONLY type="text" name="from_date" size="20" maxlength="40" value=<?php echo '"'.$sBdayBuffer.'" '.$sDateJSfrom.' '?> </font> <p></p> To: <font size=3> <INPUT READONLY type="text" name="to_date" size="20" maxlength="40" value=<?php echo '"'.$sBdayBuffer.'" '.$sDateJSto.''?> </font> <p></p> <INPUT type="text" name="keyword" size="20" maxlength="40" value="<?php echo $keyword ?>"></font> <input type=hidden name="search" value=1> <input type=hidden name="from" value="<?php echo $from_date ?>"> <input type=hidden name="to" value="<?php echo $to_date ?>"> <input type=submit name="submit" value=submit> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/49668-sql-conversion/page/3/#findComment-257531 Share on other sites More sharing options...
Barand Posted May 20, 2007 Share Posted May 20, 2007 have you tried echo $this->sql; when it doesn't work so you can see the actual submitted query? Quote Link to comment https://forums.phpfreaks.com/topic/49668-sql-conversion/page/3/#findComment-257540 Share on other sites More sharing options...
maliary Posted May 22, 2007 Author Share Posted May 22, 2007 Yes I have, The search key is passed through all the variables. But it still doesn't work. I broke down the query into 3 parts and tested the individual tables. this produces the required results when a name is passed through as the search key. $SQL="SELECT p.name_last,p.name_first, f.*,e.* FROM care_person AS p INNER JOIN care_encounter AS e ON p.pid = e.pid INNER JOIN care_test_findings_chemlab AS f ON e.encounter_nr = f.encounter_nr WHERE test_date BETWEEN '".$pn."' AND '".$cw."' OR p.name_last LIKE '$key%' "; when I try searching using both encounter number and search key. I find that it can only search using the encounter key but the search using the name stops working. $SQL="SELECT p.name_last,p.name_first, f.*,e.* FROM care_person AS p INNER JOIN care_encounter AS e ON p.pid = e.pid INNER JOIN care_test_findings_chemlab AS f ON e.encounter_nr = f.encounter_nr WHERE test_date BETWEEN '".$pn."' AND '".$cw."' AND (p.name_last LIKE '$key%' OR e.encounter_nr=$key) "; Quote Link to comment https://forums.phpfreaks.com/topic/49668-sql-conversion/page/3/#findComment-258940 Share on other sites More sharing options...
fenway Posted May 23, 2007 Share Posted May 23, 2007 I see single quotes and PHP variables...? Quote Link to comment https://forums.phpfreaks.com/topic/49668-sql-conversion/page/3/#findComment-260141 Share on other sites More sharing options...
maliary Posted May 30, 2007 Author Share Posted May 30, 2007 Finally Got it! The problem is the search key should have this %key% instead of a single key% as in encounter_nr = %key%. But now I have to trim the values. How do I do this? Quote Link to comment https://forums.phpfreaks.com/topic/49668-sql-conversion/page/3/#findComment-264743 Share on other sites More sharing options...
bubblegum.anarchy Posted May 31, 2007 Share Posted May 31, 2007 Use the php trim function: trim($key) Quote Link to comment https://forums.phpfreaks.com/topic/49668-sql-conversion/page/3/#findComment-265378 Share on other sites More sharing options...
gregor171 Posted May 16, 2009 Share Posted May 16, 2009 I think he was right from the start, as funny as it seems. Sub-query seems as a good idea for this. But since it's working now it was just an idea. Quote Link to comment https://forums.phpfreaks.com/topic/49668-sql-conversion/page/3/#findComment-835437 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.