|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Using select with PHP
Im trying to use the following functions to create a drop down box populated with information from a table but with a default value aswell.
Im trying trouble as it not outputting the first row of the table and i cant set the default value name although i can get the default id. Can anyone help?? Code: function PrintAddressForm($row, $prefix) { echo "Address Details <br> id=",$row['address_addresstype_id']; GetCombo('address_addresstype_id','addresstype_tbl ', $row['address_addresstype_id']); echo "Address Type <br>"; echo "<input type='text' name='",$prefix,"address_housenumber' value =", $row['address_housenumber'],">"; echo "House Number <br>"; echo "<input type='text' name='",$prefix,"address_road' value =", $row['address_road'],">"; echo "Road <br>"; echo "<input type='text' name='",$prefix,"address_city' value =", $row['address_city'],">"; echo "City <br>"; echo "<input type='date' name='",$prefix,"address_county' value =", $row['address_county'],">"; echo "County <br>"; echo "<input type='text' name='",$prefix,"address_postcode' value =", $row['address_postcode'],">"; echo "Post Code <br>"; echo "<input type='text' name='",$prefix,"address_email' value =", $row['address_email'],">"; echo "Email <br>"; echo "<input type='text' name='",$prefix,"address_contactphoneno' value =", $row['address_contactphoneno'],">"; echo "Contact No <br>"; } function GetCombo($ComboName, $TableName, $SelectedID) { $query3 = "SELECT * FROM $TableName"; $result3 = mysql_query($query3) or die ("Could Not Execute Query3"); $row3 = mysql_fetch_array($result3); echo "<select name=$ComboName>"; while ($row3 = mysql_fetch_array($result3)) { echo "<option value=",$row3['addresstype_id']; if ($row3['addresstype_id']==$SelectedID) echo "selected"; echo "\n",">",$row3['addresstype_name']; } echo "</select>"; } Thanks |
|
#2
|
|||
|
|||
|
what exactly do u mean by a default value
|
|
#3
|
|||
|
|||
|
and another thing, there should not be any commas before $prefix or after it, so a line should look like this
PHP Code:
and another question what is adress_contactphoneno are u trying to say the variable is $prefix_$address_contactphoneno or are u trying to say its something like $prefix is your variable and adress_contactphoneno is the rest of it, in that case u can try as it is above |
|
#4
|
|||
|
|||
|
The idea to to get a members address details from a database for them to be updated so the default should be set to the actual value from the database whilst the rest of the select should be filled with the remaining addresstypes
the prefix is used so if there is more than one address it gives them a different variable value so they can be updated. Hope this clears it up a bit |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Using select with PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|