Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,492 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,710 people online right now. Registration is fast and FREE... Join Now!




Dynamically updating dropdowns in PHP

 
Reply to this topicStart new topic

Dynamically updating dropdowns in PHP

jeansymolanza
28 Feb, 2008 - 03:47 PM
Post #1

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
CODE

<select name="buyername" id="buyername">
<?
$query="SELECT * FROM tbl_users";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"title");
$title=mysql_result($result,$i,"title");
$fname=mysql_result($result,$i,"fname");
$lname=mysql_result($result,$i,"lname");

echo
"<option>
$title $fname $lname
</option>";

$i++;
}
?>
</select> (Buyer needs to have an registered I Love Physics account) </label></td>
              </tr>
           <tr>
             <td valign="top">Buyer Address </td>
             <td valign=""><label>                 
               <textarea name="buyeraddress" cols="40" rows="5" id="buyeraddress" readonly="readonly">
             </textarea>


Whilst working on the admin "Add Purchase" page, I'd like the text area to be updated automatically with the buyer address when a certain buyer is picked from the dropdown menu. Is this possible at all? I understand that it would need the buyer id to be passed through to the textarea section of the form at this stage.

crazy.gif Lol but how?

At a later stage I have the following fields

Product Purchase - (a dropdown menu containing all the products for sale)
Quantity - (text field where the number of the products to be bought)
Cost (minus shipping) - (readonly textfield calculating product purchase price * quantity)

Paid? - has the user paid for the product already? (drop down with yes or no options)
Status - what is the current status of the ORDER (drop down menu, current options undecided)

I plan to use the same "passing through" method to work out the total cost of the product purchased using some PHP maths and the quantity entered.

This post has been edited by jeansymolanza: 28 Feb, 2008 - 03:48 PM
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Dynamically Updating Dropdowns In PHP
28 Feb, 2008 - 04:19 PM
Post #2

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

can do with a few switches.
it is all based on switches, computers. on off.

so set a switch, turn on stuff you want on the pages to be seen.

php

<?
<form>
<select name="buyerid" id="buyername">
<?
$query='SELECT * FROM `tbl_users`';
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
extract($row);
echo '<option value='.$id.'>'.$title.' '.$fname.' '.$lname.'</option>';
}
mysql_free_result($result);
?>
</select> <input type=submit></form>(Buyer needs to have an registered I Love Physics account) </label>

</td></form>
</tr>
<? if(is_numeric($_GET['buyerid'])){
//info a different table?
$sql = 'select buyer info where id='.$_GET['buyerid'];
?>
<tr>
<td valign="top">Buyer Address </td>
<td valign=""><label>
<textarea name="buyeraddress" cols="40" rows="5" id="buyeraddress" readonly="readonly">
</textarea>
<?
//set a new switch?
} ?>

?>

User is offlineProfile CardPM
+Quote Post

jeansymolanza
RE: Dynamically Updating Dropdowns In PHP
28 Feb, 2008 - 05:13 PM
Post #3

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
How is a new switch set?
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Dynamically Updating Dropdowns In PHP
29 Feb, 2008 - 07:49 AM
Post #4

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

depends what you want to set.
would need more info what you want to do next.

Product Purchase - (a dropdown menu containing all the products for sale)
Quantity - (text field where the number of the products to be bought)
Cost (minus shipping) - (readonly textfield calculating product purchase price * quantity)
quote:
Paid? - has the user paid for the product already? (drop down with yes or no options)
Status - what is the current status of the ORDER (drop down menu, current options undecided)

now that have the address, shipping options?



User is offlineProfile CardPM
+Quote Post

jeansymolanza
RE: Dynamically Updating Dropdowns In PHP
29 Feb, 2008 - 04:03 PM
Post #5

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
There are 2 tables in my database, once called tbl_users and tbl_products.

Upon selecting the buyer name from the dropdown (which is extracted from tbl_users), their address appears automatically in the textfield below.

Product puchase extracts data from tbl_products. The default quantity is 1. Upon selecting a product purchase the value in the cost textfield is set automatically (extracted from tbl_products). When the quantity is changed then the cost changes according (i.e numerical value * product price in table).

I hope this explanation helps.

This post has been edited by jeansymolanza: 29 Feb, 2008 - 04:27 PM
User is offlineProfile CardPM
+Quote Post

jeansymolanza
RE: Dynamically Updating Dropdowns In PHP
29 Feb, 2008 - 06:06 PM
Post #6

New D.I.C Head
*

Joined: 20 Feb, 2008
Posts: 34


My Contributions
No worries lol I sorted it out by splitting the page up into different pages.

Thanks for the help though, I used your code as a reference.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:46PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month