Jump to content

Recommended Posts

 

 

Hi guys,

 

I have a form that am using to search for data in my database. This issue is I have to click on the submit button twice for the search to return the correct search results. That is the first time I search I get no data

but the second time I search I get data with the same search parameters both times.

 

Here is the form. The search parameters are passed into the function

 

<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>

<B><?php echo $LDSearchWordPrompt ?></B></font><p>
<font size=3>
<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="sid" value=<?php echo $sid ?>>
<input type=hidden name="lang" value=<?php echo $lang ?>>
<input type=hidden name="editmode" value=<?php echo $editmode ?>>
<INPUT type="image" <?php echo createLDImgSrc($root_path,'searchlamp.gif','0','absmiddle') ?>>          
<a href="javascript:gethelp('lab.php','search','<?php echo $mode ?>','<?php echo $linecount ?>','<?php echo $datafound ?>')"><img <?php echo createLDImgSrc($root_path,'hilfe-r.gif','0','absmiddle') ?>></a>
       
<input type=hidden name="from" value="<?php echo $from_date ?>">
<input type=hidden name="to" value="<?php echo $to_date ?>"> 

</FORM>

 

The function

 

$encounter=&$lab_obj->searchEncounterLabResults($keyword,$pagen->MaxCount(),$pgx,$oitem,$odir,$from_date,$to_date);;      

 

 

To this function in another page:

 

function searchEncounterLabResults($key='',$add_opt='',$limit=FALSE,$len=30,$so=0,$from_date='',$to_date=''){
	global $db, $sql_LIKE;

  $from_date = explode ("/",  $from_date);
      $queryFrom =   $from_date[2].  $from_date[1].  $from_date[0]; 
      $pn = $queryFrom;
      $to_date = explode ("/",$to_date);
      $queryTo =  $to_date[2]. $to_date[1]. $to_date[0];
      $cw =  $queryTo;  


	if(empty($key)) return FALSE;


	  $this -> sql="SELECT p.pid, p.name_last,p.name_first,p.sex, f.encounter_nr, f.type,f.batch_nr,f.findings_date AS thedate
                        FROM   care_person AS p
                        INNER JOIN  care_encounter AS e ON p.pid = e.pid
                        INNER JOIN   care_test_findings_patho AS f ON e.encounter_nr = f.encounter_nr  WHERE  findings_date  BETWEEN $pn AND $cw AND (p.name_last LIKE '%$key%' OR p.name_first LIKE '%$key%' OR e.encounter_nr LIKE '%$key%') AND verified='2'
                        UNION  
                        SELECT p.pid, p.name_last,p.name_first,p.sex, g.encounter_nr, g.type,g.batch_nr,g.test_date AS thedate
                        FROM   care_person AS p
                        INNER JOIN  care_encounter AS e ON p.pid = e.pid
                        INNER JOIN care_test_findings_chemlab AS g ON e.encounter_nr = g.encounter_nr WHERE  test_date  BETWEEN $pn AND $cw AND (p.name_last LIKE '%$key%' OR p.name_first LIKE '%$key%' OR e.encounter_nr LIKE '%$key%') AND verified='2'
                        UNION   
                        SELECT p.pid, p.name_last,p.name_first,p.sex, h.encounter_nr, h.type,h.batch_nr,h.findings_date AS thedate
                        FROM   care_person AS p
                        INNER JOIN  care_encounter AS e ON p.pid = e.pid
                        INNER JOIN care_test_findings_baclabor AS h ON e.encounter_nr = h.encounter_nr WHERE  findings_date  BETWEEN $pn AND $cw AND (p.name_last LIKE '%$key%' OR p.name_first LIKE '%$key%' OR e.encounter_nr LIKE '%$key%') AND verified='2'  ORDER BY batch_nr ";   
                                            
}	                    



 

 

 

Link to comment
https://forums.phpfreaks.com/topic/53608-click-on-submit-button-twice/
Share on other sites

   

Guys,

 

The problem actually comes from this part. Because the submit button works with a single click when i removed it. Is there an alternative way to work on the submitted date range? This code just converts the date format from dd/mm/yyyy to yyyy/mm/dd

 

      $from_date = explode ("/",  $from_date);
      $queryFrom =   $from_date[2].  $from_date[1].  $from_date[0]; 
      $pn = $queryFrom;
      $to_date = explode ("/",$to_date);
      $queryTo =  $to_date[2]. $to_date[1]. $to_date[0];
      $cw =  $queryTo; 

 

 

I realise that sessions could be behind this. Because when I log-in It is only on the first attempt at the archive that it does not out the search results but finds 0 data, all other subsequent searches produce the required output.

 

After I log-out and log-in however It does not search on the first attempt.

 

 

Guys,

 

Anyone with an idea on what is causing this???? :o

 

On the second search attempt when it is working correctly The sql statement is printed out twice when I echo $this->sql so is the key word when I echo $key.

 

When the search is producing 0 results, the $this->sql is printed out only once and so is the key.

 

What's going on??? 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.