1

I am trying to display two seperate items on the same line in a HTML form using a PHP loop to auto populate it. This is the PHP/HTML form:

           <select class="form-control" name="list" title="pick a type">
              <?php if(count($postOpts)) { ?>
              <?php foreach($postOpts as $row) { ?>
              <option value="<?= $row["name"] ?>"><?= $row["price"] ?></option>
              <?php } ?>
              <?php } else { ?>
              <option value="<?= $post->getDefaultPrice() ?>"><?= "Default Shipping Option - $".$post->getDefaultPrice() ?></option>
              <?php } ?>
           </select>

I can have either the price or the name displaying, but not both on the same line.

Can anyone help?

2
  • <option value="<?= $row["name"] ?>"><?= $row["price"] ?></option> Commented Oct 29, 2015 at 10:35
  • like e.g.: <option value="<?= $row["name"] ?>"><?= $row["name"] . $row["price"] ?></option> Commented Oct 29, 2015 at 10:57

3 Answers 3

1

May be try this,

<option value="<?= $row["name"] ?>"><?= $row["name"] ."( $".$row["price"].")" ?></option>
Sign up to request clarification or add additional context in comments.

2 Comments

Sure:) Glad it helped you.
@NiranjanNRaju Bhai, full traffic jam in silkboard. :D Without accepting, where he went. People answering this question as OP didn't got right answer.
0

check the argument on here

if(count($postOpts)) {

should be

empty($postOpts)


<select class="form-control" name="list" title="pick a type">
  <?php 
  if(empty($postOpts)) { 
       foreach($postOpts as $row) 
       { 
        ?>
            <option value="<?php echo $row["name"] ?>">
                <?php echo $row["price"] ?>
            </option>
      <?php 
        } 
    } else { 
        ?>
          <option value="<?php echo $post->getDefaultPrice() ?>"> 
            <?php echo "Default Shipping Option - $".$post->getDefaultPrice() ?>
          </option>
      <?php 
    } 
  ?>
</select>

Comments

0

Replace <option value="<?= $row["name"] ?>"><?= $row["price"] ?></option> with <option value="<?= $row['name'] ?>"><?= $row['price'] ?></option> and let me know what you are getting now ? You need to use single quote inside double quote or vice versa.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.