Jump to content

[SOLVED] Pre-filling Forms with Database Information


virtuexru

Recommended Posts

OK. I have an update record form I'm building. I can pre-fill the text fields, but have no idea how to pre-file the drop down fields?

 

For example:

 

        <?php
        $query  = "SELECT * FROM vehicles WHERE veh_id = '$id' LIMIT 1";

        $result = mysql_query($query) or die(mysql_error());
        while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
        ?>
            // KNOW HOW TO PRE-FILL
            <tr bgcolor="#E9E9E9">
            	<td style="padding-left: 5px;"><strong>Model:</strong></td>
                <td><input type="text" name="_model" value="<?php echo "{$row['_model']}"; ?>" size="25"></td>
            </tr>
            // DONT KNOW HOW TO PRE-FILL
            <tr bgcolor="#E9E9E9">
            	<td style="padding-left: 5px;"><strong>Odometer:</strong></td>
                <td><select name="_odometer">
                <option value=""></option>
                <option value="Actual">Actual</option>
                <option value="Not Actual">Not Actual</option>
                <option value="TMU">TMU</option>
                </select>
                </td>
            </tr>
            <?php
            }
            ?>

 

Any help? How would I fill-in a drop down with MySQL record data?

           

 

 

Link to comment
Share on other sites

something like:

<?php
        $query  = "SELECT * FROM vehicles WHERE veh_id = '$id' LIMIT 1";

        $result = mysql_query($query) or die(mysql_error());
        while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
        ?>
            // KNOW HOW TO PRE-FILL
            <tr bgcolor="#E9E9E9">
            	<td style="padding-left: 5px;"><strong>Model:</strong></td>
                <td><input type="text" name="_model" value="<?php echo "{$row['_model']}"; ?>" size="25"></td>
            </tr>
            // DONT KNOW HOW TO PRE-FILL
            <tr bgcolor="#E9E9E9">
            	<td style="padding-left: 5px;"><strong>Odometer:</strong></td>
                <td><?php 

echo '<select name="_odometer">';  
echo '<option>Choose Option</option>';

while($row = mssql_fetch_array($rs))
{  
  echo '<option value="'.$row[0].'">'.$row[0].'</option>';
   
}  

echo '</select>'; ?>
                </td>
            </tr>
            <?php
            }
            ?>

Link to comment
Share on other sites

Grab the value of the drop down from the database the do something like:

 

<select name="_odometer">
<option value=""></option>
<option value="Actual"<?=($row['_odometer'] == "Actual") ? " selected" :NULL;?>>Actual</option>
<option value="Not Actual"<?=($row['_odometer'] == "NotActual") ? " selected" :NULL;?>>Not Actual</option>
<option value="TMU"<?=($row['_odometer'] == "TMU") ? " selected" :NULL;?>>TMU</option>
</select>

Link to comment
Share on other sites

Grab the value of the drop down from the database the do something like:

 

<select name="_odometer">
<option value=""></option>
<option value="Actual"<?=($row['_odometer'] == "Actual") ? " selected" :NULL;?>>Actual</option>
<option value="Not Actual"<?=($row['_odometer'] == "NotActual") ? " selected" :NULL;?>>Not Actual</option>
<option value="TMU"<?=($row['_odometer'] == "TMU") ? " selected" :NULL;?>>TMU</option>
</select>

 

Worked perfectly man, thanks a ton.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.