Edit record + display correct menu choice

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Edit record + display correct menu choice

Post by bob_the _builder »

Hey,

I have a edit data form .. the "city" field is a list/menu .. How can I make it so it so it uses the "echo" function to show the choice saved in the database rather than the first choice of the menu?

Code: Select all

<table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr> 
   <td><form name="address" method="post" action="update_data.php?page=edit">
       <table width="100%" border="0">
         <tr> 
           <td><font face="Tahoma">First Name: </font></td>
           <td><font face="Tahoma"> 
             <input name="fname" type="text" size="30" value="<?php echo $FirstName; ?>">
             </font></td>
         </tr>
         <tr> 
           <td><font face="Tahoma">Last Name:</font></td>
           <td><font face="Tahoma"> 
             <input name="lname" type="text" size="30" value="<?php echo $LastName; ?>">
             </font></td>
         </tr>
         <tr> 
           <td><font face="Tahoma">Email:</font></td>
           <td><font face="Tahoma"> 
             <input name="email" type="text" size="30" value="<?php echo $Email; ?>">
             </font></td>
         </tr>
         <tr> 
           <td><font face="Tahoma">Phone No:</font></td>
           <td><font face="Tahoma">
             <input name="phone" type="text" size="30" value="<?php echo $Phone; ?>">
             </font></td>
         </tr>
         <tr> 
           <td><font face="Tahoma">Cell No:</font></td>
           <td><font face="Tahoma">
             <input name="cel" type="text" size="30" value="<?php echo $Cel; ?>">
             </font></td>
         </tr>
         <tr>
           <td><font face="Tahoma">Fax No:</font> </td>
           <td><font face="Tahoma">
             <input name="fax" type="text" size="30" value="<?php echo $Fax; ?>">
             </font></td>
         </tr>
         <tr> 
           <td><font face="Tahoma">Street No:</font></td>
           <td><font face="Tahoma"> 
             <input name="no" type="text" size="5" value="<?php echo $No; ?>">
             </font></td>
         </tr>
         <tr> 
           <td><font face="Tahoma">Street:</font></td>
           <td><font face="Tahoma"> 
             <input name="street" type="text" size="30" value="<?php echo $Street; ?>">
             </font></td>
         </tr>
         <tr> 
           <td><font face="Tahoma">City:</font></td>
           <td><font face="Tahoma"> 
             <select name="city">
               <option>Australia</option>
               <option>Canada</option>
               <option>US</option>
             </select>
    
             </font></td>
         </tr>
         <tr> 
           <td colspan="2"><div align="center"> <font face="Tahoma"> 
          <input type="hidden" name="id" value="<?php echo $id; ?>">
          <input type="submit" name="Submit" value="Submit">
               </font></div></td>
         </tr>
       </table>
     </form></td>
Thanks
Last edited by bob_the _builder on Sat Aug 28, 2004 8:13 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Hey,

Thats not really what im after .. I need something like:

Code: Select all

<select name="city">
  <option <?php echo $currentCity=='Australia' ? 'selected' : ''?>>Australia</option>
   <option <?php echo $currentCity=='Canada' ? 'selected' : ''?>>Canada</option>
   <option <?php echo $currentCity=='US' ? 'selected' : ''?>>US</option>
</select>
But that still displays the first option in the list menu .. Not the choice that is within the database ..

Thanks
Last edited by bob_the _builder on Sat Aug 28, 2004 8:14 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the linked page's examples can do such things.
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Hey,

The example I posted above .. It should work?

Do you notice any error in it?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

assuming $currentCity is set correctly, I don't see a problem with that specific code.
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Hey,

The list/menu name is filter and the mysql field is called filter:

Code: Select all

<select name="filter" size="3">
   <option <?php echo $currentfilter=='Australia' ? 'selected' : ''?>>Australia</option>
   <option <?php echo $currentfilter=='Canada' ? 'selected' : ''?>>Canada</option>
   <option <?php echo $currentfilter=='US' ? 'selected' : ''?>>US</option>
</select>
To me that should work .. It should highlight the option that is in the database .. ie Auckland if the "filter" field = Auckland

$currentfilter

Been the name of the field .. filter?

Im not sure where the variable $current comes from?

Thanks
Last edited by bob_the _builder on Sat Aug 28, 2004 8:15 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql will not automatically attach the two.. since data can come from anywhere. You will have to retrieve the data needed from mysql and store it in the variable of your choice.

In the link I provided originally, Think Pink's last post in the thread has the final code used to print the options. This code is similar to the code you will need.
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Post by bob_the _builder »

Hey,

Thanks .. Im a noobie .. It doesnt make alot of sence me :oops:

I have no idea on how to sort it .. I thought the code I posted above would do the job .. as it does to echo back the data in a text box .. but I guess not.

Thanks
Post Reply