Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    option Default on pull-down menu

    Trying to show a default (or current value) to the first line of a pull down option. Value will only show if I refresh the page. In the example below, the default value is in the line:

    echo "<option value={$row['code']}></option>";

    Not sure if this is where the problem lies. The pull does show the value but like I said only after refreshing the page.

    Code:
    $query = "SELECT * FROM wos WHERE disciplineID=1 AND woID='{$getwoID}'";
    		if (!($result = @mysql_query ($query, $connection)))
    			die("die 3");
    
    		$row = @ mysql_fetch_array($result);
    
    		echo "<p>WO Number: <b>{$row['woID']}</b></p>";
    		echo "<p>Equipment : <b>{$row['equipmentID']}</b></p>";	
    					
    		// problem code field 
    		require './includes/dbConnection.inc';
    		if (!($connection = @ mysql_connect($db_host, $db_user, $db_pass)))
    			die("Could not connect to sql");
    
    		if (!mysql_select_db($db_name, $connection))
    			die("Could not connect to database!");
    		
    		$query_code = "SELECT * FROM troublecodes WHERE PG=1 ORDER      BY code ASC";
    ?>		
    		<label for="code" class="required">Select Trouble Code: </label>&nbsp;
    		<select name='code' id='code' width="200">
    
    <?php	$result_code = mysql_query($query_code);
    		echo "<option value={$row['code']}></option>";
    		while ($line = mysql_fetch_array($result_code)) {
    		echo "<option value='".$line['code']."'>" .$line['code']. " - ".$line['description']."</option>";
    		}

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    PHP Code:
    $result_code mysql_query($query_code);
    while (
    $line mysql_fetch_array($result_code)) {
        if(
    $row['code'] == $line['code']){
            echo 
    "<option value='".$line['code']."' SELECTED>" .$line['code']. " - ".$line['description']."</option>";
        } else {
            echo 
    "<option value='".$line['code']."'>" .$line['code']. " - ".$line['description']."</option>";
        }


  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much! That did it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •