Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2010
    Posts
    136

    Unanswered: Problem in SELECT option with condition

    Hi..

    I got problem in logic on my problem in select option.

    Here is my scenario.

    I have select option which has a compound list:

    example:

    P28
    P30
    P32
    P33
    P35


    and I have tables which has a total count of
    compound that was already transact.

    for example I already transact
    10 P28 compound.

    it will save in kanban_checker table field Total.

    and I have parameter_settings table which has the maximum and minimum per compound:

    fields----------data
    P28------------P28
    P28_max-----10
    P28_min------6
    P30------------P28
    P30_max-----10
    P30_min------6
    P32------------P28
    P32_max-----10
    P32_min------6
    P33------------P28
    P33_max-----10
    P33_min------6


    now the logic is:

    if P28 total = P28_max then notify that he already reach the maximum..it will not produce P28 because he already reach the maximum.

    if P28 total = P28_min then produce P28.

    same with other compound.

    Now, I got a problem in coding and logic, because in the select option I'm not the one who code it.. I just one who need to add the additional function..

    here is the code for select option and the function that was created by other,

    Code:
    $smarty->assign('text_name1','Compound Code'); 
     $smarty->assign('compoundIndexValue', array('0',  'P28',  'P30',  'P32',  'P33',  'P35',  'P35M',  'P38',  'P40', 'P41',  'P42',  'P43', 'P46', 'P47', 'PXX', 'P35W'));
    
     <tr>
                <td class="tdMainText">{$text_name1}</td>
                
                <td> <select class="tdMainElement" id="selCompound"  onchange="isSelected('selCompound','txtLotCode')" onclick="clearNotify()" onblur="this.focus();" onkeypress="return false">{html_options values=$compoundIndexValue output=$names selected="0"} </select> </td>
                </tr>
    
    <script type="text/javascript">
    function isSelected(obj1, obj2) {
    
         if (!document.getElementById(obj1).disabled) {
             document.getElementById(obj1).disabled = true;
         }       
                 
         if (document.getElementById('clear').disabled) { 
             document.getElementById('clear').disabled = false; //enable it 
         }
    
         if ((document.getElementById('chkDownGrade') != null)) {
            if (!document.getElementById('chkDownGrade').disabled) {     
               document.getElementById('chkDownGrade').disabled = true;
            }
         }
         
         
         if (document.getElementById(obj2).disabled) {
             document.getElementById(obj2).disabled = false;
         }
             document.getElementById(obj2).focus();
             document.getElementById(obj2).focus(); 
             
         //notify("Gain Maximum Total");  
    
    }
    
    function disable() {
                 if (!document.getElementById('clear').disabled) {
                     document.getElementById('clear').disabled = true;
                 }
                 else {  
                     document.getElementById('clear').disabled = false;
                 } 
    
    }
    
    function clearNotify() {
        
       if (document.getElementById('notice') != null) {
          document.getElementsByTagName('body')[0].removeChild(document.getElementById('notice')) //>> clear the box    } 
       }
    </script>
    and here is the code that I tried to add:

    Code:
    $compound = mysql_real_escape_string($_POST['compound']);
            $sql = "SELECT 
                    P28, P28_max, P28_min,
                    P30, P30_max, P30_min,
                    P32, P32_max, P32_min,
                    P33, P33_max, P33_min,
                    P35, P35_max, P35_min,
                    P35M, P35M_max, P35M_min,
                    P35W, P35W_max, P35W_min,
                    P38, P38_max, P38_min,
                    P41, P41_max, P41_min,
                    P42, P42_max, P42_min,
                    P43, P43_max, P43_min,
                    P46, P46_max, P46_min
                    FROM parameter_settings";
            $res_pcode = mysql_query($sql, $con);
            
            while($row = mysql_fetch_assoc($res_pcode)){
                $P28 = $row['P28'];
                $P28_max = $row['P28_max'];
                $P28_min = $row['P28_min'];
            
                $P30 = $row['P30'];
                $P30_max = $row['P30_max'];
                $P30_min = $row['P30_min'];
                
                $P32 = $row['P32'];
                $P32_max = $row['P32_max'];
                $P32_min = $row['P32_min'];
                
                $P33 = $row['P33'];
                $P33_max = $row['P33_max'];
                $P33_min = $row['P33_min'];
                
                $P35 = $row['P35'];
                $P35_max = $row['P35_max'];
                $P35_min = $row['P35_min'];
               
                $P35M = $row['P35M'];
                $P35M_max = $row['P35M_max'];
                $P35M_min = $row['P35M_min'];
                
                $P35W = $row['P35W'];
                $P35W_max = $row['P35W_max'];
                $P35W_min = $row['P35W_min'];
                
                $P38 = $row['P38'];
                $P38_max = $row['P38_max'];
                $P38_min = $row['P38_min'];
                
                $P41 = $row['P41'];
                $P41_max = $row['P41_max'];
                $P41_min = $row['P41_min'];
                
                $P42 = $row['P42'];
                $P42_max = $row['P42_max'];
                $P42_min = $row['P42_min'];
                
                $P43 = $row['P43'];
                $P43_max = $row['P43_max'];
                $P43_min = $row['P43_min'];
                
                $P46 = $row['P46'];
                $P46_max = $row['P46_max'];
                $P46_min = $row['P46_min'];
                
                $P47 = $row['P47'];
                $P47_max = $row['P47_max'];
                $P47_min = $row['P47_min'];
            }
           // $sub_lotcode = substr($lotCode, 9, 4);
               
            $sql = "SELECT PCODE, total FROM kanba_checker WHERE PCODE = '$sub_lotcode' ORDER BY PCODE";
            $res_kanban = mysql_query($sql, $con);
            
            $row_kanban = mysql_fetch_assoc($res_kanban);
            
            $PCODE = $row_kanban['PCODE'];
            $total = $row_kanban['total'];
            
            if($compound = $P28 || $total == $P28_max){
             echo "<script type='text/javascript'>alert(P28 gain total maximum)</script>";   
            }
            else{
                
            }
    but I don't know if my code and my logic is correct.

    I think I did to add function.

    But I don't know how..

    I hope someone can help me or guide me to solve my problem.

    Thank you so much..

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    From a database point of view this looks fine. I am not sure why you are pulling all information from the parameter_settings table because you are only looking at p28 and p28_max and p28_min. There is a lot of missing information for us to determine what you are trying to achieve and also whether it will work. For example, your second query is using $sub_lotcode but it is not clear where this is derived from or missing? Above where it is referenced there is a commented out line of code which says it is a substring of lotcode but we do not know what this is and whether it should have been derived above?

    A final note, is your decision making process. If we have reached the max but you have not tested if you have exceeded the max. I would have done something like $total >= $p28_max.

    If you have exceeded your max what do you want the page to achieve? At the moment you are writing a tag for executing javascript code. By itself this will not work as you need to put this into a <html> page.

    There is a syntax error with the alert as the comments should be embedded inside quotes and terminate with a semi-colon ";" as follows:

    alert("this is a test");
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Dec 2010
    Posts
    136
    Hi,

    sorry, the sublotcode should be $compound..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •