fmax Posted April 5 Share Posted April 5 Hi All Using MVC Model i am stuck on multiple dependent combobox, My first combobox model code is as follows function getCompanyName(object $pdo){ $query = "SELECT * FROM MASTER_COMPANY;"; $companyNameStmt = $pdo->prepare($query); $companyNameStmt->execute(); $companyNameresult = $companyNameStmt->fetchAll(PDO::FETCH_ASSOC); return $companyNameresult; } I want to populate to a combobox <select name="FCompName" id="company-id" class="form-select" required=""> <option value="" disabled selected>--- SELECT COMPANY ---</option> <?php ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/319693-populate-combobox-dynamically/ Share on other sites More sharing options...
Barand Posted April 5 Share Posted April 5 Loop through the returned results of your function and output the options <?php foreach (getCompanyName($pdo) as $row) { echo "<option value='{$row['id']}'>{$row['name']}</option>" ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/319693-populate-combobox-dynamically/#findComment-1620520 Share on other sites More sharing options...
fmax Posted April 5 Author Share Posted April 5 8 minutes ago, Barand said: Loop through the returned results of your function and output the options <?php foreach (getCompanyName($pdo) as $row) { echo "<option value='{$row['id']}'>{$row['name']}</option>" ; } ?> (): Argument #1 ($pdo) must be of type object, null given Quote Link to comment https://forums.phpfreaks.com/topic/319693-populate-combobox-dynamically/#findComment-1620521 Share on other sites More sharing options...
Barand Posted April 5 Share Posted April 5 Then use the actual name of your PDO connection object instead of $pdo. My apologies for not being psychic. 1 Quote Link to comment https://forums.phpfreaks.com/topic/319693-populate-combobox-dynamically/#findComment-1620522 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.