We help IT Professionals succeed at work.

PHP I want to add another column to the dropdown .. so that the drop down shows

LeighJor
LeighJor asked
on
228 Views
Last Modified: 2013-12-13
Hi,
I have a PHP form with a multiple select vertical dropdown showing a column from my database. I want to add another column to the dropdown .. so that the drop down shows row1: article1 price1. row2: article2 price2. row3: article3 price3, ..
Many tthanks again
leighjor
Comment
Watch Question

Commented:
could you post your code. thanks
Yeah, if you can post some code it would be nice.

;)

Author

Commented:
Sorry , didnt want to burden you with code 1st off
Here is the form code the drop down box is populated from database

<FORM ACTION="Email.php" method=post>
<table border=0>
<tr>
<td width=15>Quantity
</td>
<td ><input type="text" name="qty" size="3" maxlength="3"></td>
</tr>

<tr>
<td>
<p>
      <label for="bname">BULBS:</label></td>
   <td><select multiple name="bname[]" id="bname">
        <option value="">Select Bulb</option>
            <?php
            while ($bname = $imageList->fetch_assoc()) {
            ?>
            <option value="<?php echo $bname['bname']; ?>"
            <?php
            if ($bname['bname'] == $bname) {
              echo ' selected="selected"';
              }
            ?>><?php echo $bname['bname']; ?>
            </option>
            <?php } ?>
      </select>  
    </p>
</td>
</tr>
<tr>
<td colspan="2" align="center"><br>
<input type="submit" value="Enter Order"></td>
</tr>
</table>
</form>
I cleaned up your code a little:

<FORM ACTION="Email.php" method=post>
<table border=0>
<tr>
<td width=15>Quantity
</td>
<td ><input type="text" name="qty" size="3" maxlength="3"></td>
</tr>
<tr>
<td>
<p>
      <label for="bname">BULBS:</label></td>
   <td><select multiple name="bname[]" id="bname">
        <option value="">Select Bulb</option>
            <?php
                  while($bname = $imageList->fetch_assoc())
                   {
                         $selected = ($bname['bname'] == $bname) ? 'selected="selected"' : '';
                              echo '<option value="'.$bname['bname'].'" '.$selected.'>'.$bname['bname'].'</option>';
                         }
                  ?>
      </select>  
    </p>
</td>
</tr>
<tr>
<td colspan="2" align="center"><br>
<input type="submit" value="Enter Order"></td>
</tr>
</table>
</form>

I still don't know what you mean by adding another column.

Author

Commented:
OK the drop down box at the moment is -- imagine in drop down box is:
apple
banana
pear
apricot

I want it to show:
apple         20c
banana      20c
pear          30c
apricot      40c

where the 2nd column is drawn from database


I then want to xply the number input from the 1st input box "qty" by the 20c and
be able to receive through email that customer x wants "qty apples" total cost "qty x 20c"

Thats it  but just how to get 2 columns would be great help
Ta
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
basically you would have it
just use the example as above, and put it in two dive
so it looks like this

<option value="<?php echo $bname['bname']; ?>"><div class="bname"><?php echo $bname['bname']; ?></div><div class="bprice"><?php echo $bname['bprice']; ?></div></option>

then set the styles of each of the divs to have a certain width.
that should work. didnt test it though.

Commented:
beat me to it,
stefanaichholzer's example should work well too.

Author

Commented:
Fine I'll push you a bit further though your quite welcome to quit and atke the points
So how do I xply the qty by the correct price given that  more than one price may be returned from the multiple select
Cheers
Usually you will have one price per item in the DB, meaning you can multiply it easily by the value from the select. I don't see a problem.

Author

Commented:
Thanks <bold>stefanaichholzer </bold>
I'll see how I go
I'm glad I could help, if you need anything else just let me know! ;)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.