Jump to content
Sign in to follow this  
samuvk

How to fill a combobox in php from postgresql

Recommended Posts

I would like to fill a combobox from my data in a table of my postgresql database.

Here is my code: but I'm getting the combobox empty.

<html>
        <body>
                <select>
                        <?php
                                $db = pg_connect('host=localhost dbname=test user=myusername password=mypassword') or die ("Could not connect to DB");
                                $sql = pg_query(sprintf("SELECT City FROM Cities"));
                                while ($row = pg_fetch_assoc($sql))
                                {
                                        echo "<option value=$row[City]>$row[City]</option>";
                                }
                                pg_close($db);
                        ?>
                </select>
        </body>
</html>

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

×
×
  • 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.