I built a method in PHP that generates dynamic dropdowns based on a few parametric inputs.
It was working just fine, except for one, which happened to be the field describing how the item was constructed. In our case, the only value after "GROUP BY" was 'Bolted'.
The dropdown generator has a 'Selected' determination check, and it wasn't triggering the correct item on the construction field. Commence bug chasing.

After some head scratching and some attempts at using PHP's trim() and filtering, I went to the view source to see what my outputs were specifically.

There was an extra line break after the string.
I thought trim was supposed to take care of that with default settings. It didn't.
I went into PHPMyAdmin and edited the construction field, and attempted to mash delete. No luck.
Then I found this on StackExchange:


update mytable SET construction = TRIM(TRAILING '\n' FROM construction)

In my case, 0 records were affected. I then tried:


update mytable SET construction = TRIM(TRAILING '\r' FROM construction)

38,000 rows had it.
Bug fixed.

Here's the dynamic generator if that helps:


/**
*Dynamic Select Menu Maker
* Required Parameters are:
* $cleanPostVariable : a cleaned/filtered POST variable, so that on reload we can add a 'selected' option so that the user's selection is 'sticky'.
* $formElementName : Name the select form element you're about to create.
* $queryString : The SQL query for your option values
* $sourceField : This cooperates with your SQL query. Dictate the field that we'll be expecting the dataset to return.
*/
function pumperparts_kit_selector_SelectButton($cleanPostVariable,$formElementName,$queryString,$sourceField,$formName) {
global $myconn;
$brandRS = mysqli_query($myconn, $queryString);
if ($brandRS != false){
//echo "brandRS is a valid query and recordset
";
if(mysqli_num_rows($brandRS) == 0){
//*****Something must be wrong... No Brands Are Returned
//exit;
}else{
//Start the actual work - Generate that Select Menu.
//Initializing selectedVariable to make a mechanism that will automatically select the brand that was last selected in the dropdown menu.
$selectedVariable = "";
if (!is_null($cleanPostVariable))
{
//This will make the 'select a brand' option selected, in the event that a form has not yet been submitted with a brand value
$selectedVariable = "selected";
}
$pleaseSelect = "Please Select...";
$intendedJavascript = 'document.getElementById("' . $formName . '").submit();';
$brandListSelect = "

";
return $brandListSelect;
}
}
}