[CLOSED] Filtering dropdown box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • assgar
    New Member
    • Aug 2006
    • 41

    [CLOSED] Filtering dropdown box

    Hi I am trying to get data from a mysql database with php.
    These dynamic rows may have multiple prices between 1 and 5.
    I would like to use a drop dropdown to display these prices and
    allow the user to select the one that apply.

    I am having problems getting the dropdown to filter using the "if" statements.


    //This works
    if ($searching =="yes" && $phrase_count > 0)
    {
    //search for our search term, in the field the user specified
    //search for description and code in bill_ohip_fee_c ode and service
    // fee in bill_on_curr_ma ster
    $data = mysql_query("SE LECT c.code_id, c.fee_code,
    c.description, m.general_fee,
    m.technical_fee , m.specialist_fe e,
    m.anesthestist_ fee,
    m.non_anestheti st_fee
    FROM bill_ohip_fee_c ode c, bill_on_curr_ma ster m
    WHERE c.fee_code = m.code
    AND upper(c.$field) LIKE'%$find%'
    AND c.section_code = '$services'
    ORDER BY (c.$field)
    LIMIT 100");
    }


    while($row = mysql_fetch_arr ay($data))
    {
    $code_id = $row['code_id'];
    $fee_code = $row['fee_code'];
    $description = $row['description'];
    $general_fee = $row['general_fee'];
    $technical_fee= $row['technical_fee'];
    $specialist_fee = $row['specialist_fee '];
    $anaesthetist_f ee= $row['anesthestist_f ee'];
    $non_anaestheti st_fee= $row['non_anesthetis t_fee'];


    //determine length of values
    $gen_len = strlen($general _fee);
    $tec_len = strlen($technic al_fee);
    $spec_len = strlen($special ist_fee);
    $ana_len = strlen($anaesth etist_fee);
    $non_len =strlen($non_an aesthetist_fee) ;

    //format fee to 2 deciaml places
    $general = sprintf("%9.2f" ,$general_fee/100);
    $technical = sprintf("%9.2f" ,$technical_fee/100);
    $specialist = sprintf("%9.2f" ,$specialist_fe e/100);
    $anaesthetist = sprintf("%9.2f" ,$anaesthetist_ fee/100);
    $non_anaestheti st = sprintf("%9.2f" ,$non_anaesthet ist_fee/100);


    /************dro p down not filtering****** *******/
    //this is not working
    //this is the dropdow box info put into an array for use use below
    $fee = "<select name=\"fee[]\">

    if($gen_len > 0)
    {
    <option value = $general> $general</option>
    }
    if($tec_len > 0)
    {
    <option value = $technical> $technical</option>
    }
    if($spec_lent > 0)
    {
    <option value = $specialist> $specialist</option>
    }
    if($ana_len > 0)
    {
    <option value = $anaesthetist> $anaesthetist</option>
    }
    if($non_len > 0)
    {
    <option value = $non_anaestheti st> $non_anaestheti st</option>
    }
    </select>";



    //this works
    //diaplay search results in rows
    echo"<tr height=\"10\">
    <td width=\"4%\" bgcolor=\"#fff8 dc\" align=\"center\ "><input
    type=\"checkbox \" name=\"fee_choi ce[]\" value=\"$code_i d\"></td>
    <td width=\"6%\" bgcolor=\"#fff8 dc\"><span
    class=\"style20 "><strong>$fee_ code</strong></span></td>
    <td width=\"3%\" bgcolor=\"#eeee e0\" height=\"10\">
    <input type=\"text\" name=\"fee_unit[]\" size=\"1\" maxlength=\"2\"
    value =\"$fee_unit\ "/></td>
    <td width=\"80%\" bgcolor=\"#eeee e0\" class=\"style20 \"> $description
    </td>
    <td width=\"5%\" align=\"left\"> $fee </td>\n";
    echo"</tr>\n";
    }
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Works fine with me. In order to track it, why don't you put an "echo $fee" statement right after the "</select>"; statement. That should give you a drop down box. You can then decode from there on.

    Ronald :cool:

    Comment

    • assgar
      New Member
      • Aug 2006
      • 41

      #3
      Originally posted by ronverdonk
      Works fine with me. In order to track it, why don't you put an "echo $fee" statement right after the "</select>"; statement. That should give you a drop down box. You can then decode from there on.

      Ronald :cool:

      Hi Ronald
      Thanks for responding.

      I don't undestand your suggestion could you demonstrate.

      The dropdown will work and show all 5 listings and that is the problem. Some of the fees will be 0.00. I am trying to filter out the 0.00 fees from being in the dropdown.

      assgar

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        First spec_len is incorrectly spelled (spec_lent).
        What you basically do is combine logic and data in a data array. In order to get something like that working you need at least to use the eval() function. But it is better to just build up the $fee option list, as follows:
        [PHP]$fee = "<select name=\"fee[]\">";
        if($gen_len > 0)
        $fee .= "<option value = $general> $general</option>";
        if($tec_len > 0)
        $fee .= "<option value = $technical> $technical</option>";
        if($spec_leng > 0)
        $fee .= "<option value = $specialist> $specialist</option>";
        if($ana_len > 0)
        $fee .= "<option value = $anaesthetist>$ anaesthetist</option>";
        if($non_len > 0)
        $fee .= "<option value = $non_anaestheti st> $non_anaestheti st</option>";
        $fee .= "</select>"; [/PHP]

        Good luck.

        Ronald :cool:

        Comment

        • assgar
          New Member
          • Aug 2006
          • 41

          #5
          Originally posted by ronverdonk
          First spec_len is incorrectly spelled (spec_lent).
          What you basically do is combine logic and data in a data array. In order to get something like that working you need at least to use the eval() function. But it is better to just build up the $fee option list, as follows:
          [PHP]$fee = "<select name=\"fee[]\">";
          if($gen_len > 0)
          $fee .= "<option value = $general> $general</option>";
          if($tec_len > 0)
          $fee .= "<option value = $technical> $technical</option>";
          if($spec_leng > 0)
          $fee .= "<option value = $specialist> $specialist</option>";
          if($ana_len > 0)
          $fee .= "<option value = $anaesthetist>$ anaesthetist</option>";
          if($non_len > 0)
          $fee .= "<option value = $non_anaestheti st> $non_anaestheti st</option>";
          $fee .= "</select>"; [/PHP]

          Good luck.

          Ronald :cool:

          Hi Ron

          Thanks again.

          A new way to build a dropdown.
          This suggested approach does display a dropdown
          box. unfortunately I am still getting fees with 0.00 showing,
          the if statement is still not filtering out the 0.00.

          Maybe I am trying the impossible,
          but if can get the filtering working it would replace 2 X 40 = 80 lines of code.

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Then test the values of the division:
            [PHP]$fee = "<select name=\"fee[]\">";
            if(($general_fe e/100) > 0)
            $fee .= "<option value = $general>$gener al</option>";
            if(($technical_ fee/100) > 0)
            $fee .= "<option value = $technical>$tec hnical</option>";
            if(($specialist _fee/100) > 0)
            $fee .= "<option value = $specialist>$sp ecialist</option>";
            if(($anaestheti st_fee/100) > 0)
            $fee .= "<option value = $anaesthetist>$ anaesthetist</option>";
            if(($non_anaest hetist_fee/100) > 0)
            $fee .= "<option value = $non_anaestheti st>$non_anaesth etist</option>";
            $fee .= "</select>"; [/PHP]

            Ronald :cool:

            Comment

            • assgar
              New Member
              • Aug 2006
              • 41

              #7
              Originally posted by ronverdonk
              Then test the values of the division:
              [PHP]$fee = "<select name=\"fee[]\">";
              if(($general_fe e/100) > 0)
              $fee .= "<option value = $general>$gener al</option>";
              if(($technical_ fee/100) > 0)
              $fee .= "<option value = $technical>$tec hnical</option>";
              if(($specialist _fee/100) > 0)
              $fee .= "<option value = $specialist>$sp ecialist</option>";
              if(($anaestheti st_fee/100) > 0)
              $fee .= "<option value = $anaesthetist>$ anaesthetist</option>";
              if(($non_anaest hetist_fee/100) > 0)
              $fee .= "<option value = $non_anaestheti st>$non_anaesth etist</option>";
              $fee .= "</select>"; [/PHP]

              Ronald :cool:
              Hi Ron
              Thanks for the help.

              It took you last suggestion to add the final piece of the puzzle.
              I was also able to reduce the code by getting rid of the strlen().

              Here is the final code.

              while($row = mysql_fetch_arr ay($data))
              {
              $code_id = $row['code_id'];
              $fee_code = $row['fee_code'];
              $description = $row['description'];
              $general_fee = $row['general_fee'];
              $technical_fee= $row['technical_fee'];
              $specialist_fee = $row['specialist_fee '];
              $anaesthetist_f ee= $row['anesthestist_f ee'];
              $non_anaestheti st_fee= $row['non_anesthetis t_fee'];

              //format fee to 2 deciaml places
              $general = sprintf("%9.2f" ,$general_fee/100);
              $technical = sprintf("%9.2f" ,$technical_fee/100);
              $specialist = sprintf("%9.2f" ,$specialist_fe e/100);
              $anaesthetist = sprintf("%9.2f" ,$anaesthetist_ fee/100);
              $non_anaestheti st = sprintf("%9.2f" ,$non_anaesthet ist_fee/100);


              /************dro p down*********** **/
              //this is the dropdow box info put into an array for use use below

              $fee = "<select name=\"fee[]\">

              if($general > 0.00)
              {
              <option value = $general> $general</option>
              }
              if($technical > 0.00)
              {
              <option value = $technical> $technical</option>
              }
              if($specialist > 0.00)
              {
              <option value = $specialist> $specialist</option>
              }
              if($anaesthetis t > 0.00)
              {
              <option value = $anaesthetist> $anaesthetist</option>
              }
              if($non_anaesth etist > 0.00)
              {
              <option value = $non_anaestheti st> $non_anaestheti st</option>
              }
              </select>";

              Comment

              Working...