#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Posts
    15
    Rep Power
    0

    inside echo html input add if else to get value


    Hi this form is a dynamic one to add or remove a new form.

    To get the database entries there have been mishaps put into the wrong fields so I want to do an if else to get the correct value.
    This is the part of the form I want to do this in:

    PHP Code:
    echo '
    <div class="col-md-3 col-sm-12 col-xs-12"><label>Price2</label>
      <div class="input-group input-group">
                                    <span class="input-group-addon">'
    .CURRENCY.'</span>
                                    <input type="text" class="form-control calculate invoice_product_price txt" id="job_mat_retail[]" name="job_mat_retail[]" aria-describedby="sizing-addon1" placeholder="0.00" value="'
    .$job_mat_retail.'">
                                </div>
    </div>
     <div class="clear"></div>
     </div>
     

       </div>'
    ;
       
      } 
      
      
    $z++;
    ?> 
    I want to change the value="'.$job_mat_retail.'"> to be something like this:

    PHP Code:
    value="'<?php if ($job_mat_retail $job_mat_cost):
        echo 
    $job_mat_retail;
    elseif (
    $job_mat_retail ==  $job_mat_cost): 
        echo 
    $job_mat_retail;
    else:
       if (
    $job_mat_retail $job_mat_cost):
    echo 
    $job_mat_cost;
    endif;
    ?>'">
    but it won't work within the echo of the whole form.

    Thanks
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,079
    Rep Power
    4101
    Do your if/else logic above the echo statement and store the proper value into a variable, then use that variable in the echo.
    PHP Code:
    $value '';
    if (
    $job_mat_retail $job_mat_cost){
        
    $value $job_mat_retail
    } else if (
    $job_mat_retail ==  $job_mat_cost){
        
    $value $job_mat_retail
    } else if (
    $job_mat_retail $job_mat_cost){
        
    $value $job_mat_cost
     
    }
    echo 

    <div class="col-md-3 col-sm-12 col-xs-12"><label>Price2</label> 
      <div class="input-group input-group"> 
                                    <span class="input-group-addon">'
    .CURRENCY.'</span> 
                                    <input type="text" class="form-control calculate invoice_product_price txt" id="job_mat_retail[]" name="job_mat_retail[]" aria-describedby="sizing-addon1" placeholder="0.00" value="'
    .$value.'"> 
                                </div> 
    </div> 
     <div class="clear"></div> 
     </div> 
      


       </div>'

    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Posts
    15
    Rep Power
    0
    Very cool thanks, I tried to do it before but without the value = ''
    thanks again.
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,780
    Rep Power
    4536
    You should get out of the bad habit of echoing HTML code as soon as you can. Your HTML code should have as little PHP as possible.

    Do your logic and work in the PHP section, then output the HTML with simple <?=$var?> instances to output PHP values. Or maybe a little ternary operator if you need some simple logic, <?=(isset($var1))?$var1:''?>.

    Or better yet, go async and have a pure separation. I'm amazed how easy it is to do this nowadays with jquery and the like. This is presentation-level **** I could only dream of 10 years ago when I was hot & heavy into PHP.

    -John
    -- Cigars, whiskey and wild, wild women. --
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Posts
    15
    Rep Power
    0
    Originally Posted by kicken
    Do your if/else logic above the echo statement and store the proper value into a variable, then use that variable in the echo.
    PHP Code:
    $value '';
    if (
    $job_mat_retail $job_mat_cost){
        
    $value $job_mat_retail
    } else if (
    $job_mat_retail ==  $job_mat_cost){
        
    $value $job_mat_retail
    } else if (
    $job_mat_retail $job_mat_cost){
        
    $value $job_mat_cost
     
    }
    echo 

    <div class="col-md-3 col-sm-12 col-xs-12"><label>Price2</label> 
      <div class="input-group input-group"> 
                                    <span class="input-group-addon">'
    .CURRENCY.'</span> 
                                    <input type="text" class="form-control calculate invoice_product_price txt" id="job_mat_retail[]" name="job_mat_retail[]" aria-describedby="sizing-addon1" placeholder="0.00" value="'
    .$value.'"> 
                                </div> 
    </div> 
     <div class="clear"></div> 
     </div> 
      


       </div>'

    Howdy if I am to add a third variable is this how I would do it?

    PHP Code:
    $value '';
    if (
    $job_mat_retail $job_mat_cost){
        
    $value $job_mat_retail
    } else if (
    $job_mat_retail ==  $job_mat_cost){
        
    $value $job_mat_retail
    } else if (
    $job_mat_retail $job_mat_cost){
        
    $value $job_mat_cost;
     } else if (
    $job_value $job_mat_retail || $job_value $job_mat_cost ){
        
    $value $job_value;
    } else if (
    $job_value ==  $job_mat_retail || $job_value ==  $job_mat_cost ){
        
    $value $job_value;
    } else if (
    $job_value $job_mat_retail){
        
    $value $job_mat_retail;
    } else if (
    $job_value $job_mat_cost ){
        
    $value $job_mat_cost 
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Posts
    15
    Rep Power
    0
    Actually it won't work in the input field, is it because it is coming from another table? You see old records have the value in all or none in the jb_job_material table but then there was some only put into the jb_jobs_data table, the jb_job_data.job_value column. As it shows for each result it is coming from the jb_job_material table.
    I am finding it hard to correct the old entries. Going forward I am only going to use the jb_job_material.job_mat_cost for all entries into the database.

    Code:
    "SELECT
    jb_job_data.id, jb_job_data.job_value, jb_job_material.id, jb_job_material.job_id, jb_job_material.job_mat_cost, jb_job_material.job_mat_retail, jb_job_material.job_mat_qty, jb_job_material.job_mat_desc FROM jb_job_data, jb_job_material WHERE jb_job_data.id = jb_job_material.job_id AND job_id = '".$job_id."'"
    Do you have any magical ideas to get the correct result so that I can create invoices?
    Thanks for your help.

IMN logo majestic logo threadwatch logo seochat tools logo