Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2007-10-03
12
Medium Priority
?
203 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
0
Comment
Question by:LeighJor
  • 5
  • 4
  • 3
12 Comments
 
LVL 6

Expert Comment

by:paulp75
ID: 20012198
could you post your code. thanks
0
 
LVL 9

Expert Comment

by:stefanaichholzer
ID: 20012284
Yeah, if you can post some code it would be nice.

;)
0
 

Author Comment

by:LeighJor
ID: 20012363
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>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:stefanaichholzer
ID: 20012413
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.
0
 

Author Comment

by:LeighJor
ID: 20012466
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
0
 
LVL 9

Accepted Solution

by:
stefanaichholzer earned 2000 total points
ID: 20012505
Something like this maybe?

<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']*$bname['price']).'" '.$selected.'>'.$bname['bname']. ' '.$bname['price'].'</option>';
                         }
                  ?>
      </select>  
    </p>
</td>
</tr>
<tr>
<td colspan="2" align="center"><br>
<input type="submit" value="Enter Order"></td>
</tr>
</table>
</form>
0
 
LVL 6

Expert Comment

by:paulp75
ID: 20012530
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.
0
 
LVL 6

Expert Comment

by:paulp75
ID: 20012538
beat me to it,
stefanaichholzer's example should work well too.
0
 

Author Comment

by:LeighJor
ID: 20012566
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
0
 
LVL 9

Expert Comment

by:stefanaichholzer
ID: 20012581
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.
0
 

Author Comment

by:LeighJor
ID: 20012663
Thanks <bold>stefanaichholzer </bold>
I'll see how I go
0
 
LVL 9

Expert Comment

by:stefanaichholzer
ID: 20012671
I'm glad I could help, if you need anything else just let me know! ;)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question