Jump to content

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/319693-populate-combobox-dynamically/
Share on other sites

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

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.