Page 1 of 1

Edit record + display correct menu choice

Posted: Sat Aug 28, 2004 12:25 am
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

Posted: Sat Aug 28, 2004 12:30 am
by feyd

Posted: Sat Aug 28, 2004 5:13 pm
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

Posted: Sat Aug 28, 2004 5:22 pm
by feyd
the linked page's examples can do such things.

Posted: Sat Aug 28, 2004 5:57 pm
by bob_the _builder
Hey,

The example I posted above .. It should work?

Do you notice any error in it?

Thanks

Posted: Sat Aug 28, 2004 6:01 pm
by feyd
assuming $currentCity is set correctly, I don't see a problem with that specific code.

Posted: Sat Aug 28, 2004 6:34 pm
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

Posted: Sat Aug 28, 2004 6:44 pm
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.

Posted: Sat Aug 28, 2004 7:01 pm
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