I can't get the select form list to show the company's ticker symbol. I've tried various combinations of quotes and braces.

Below is part of my controller file and my views file.

Any thoughts?

Here is code for the beginning of my controller:

                // configuration

                // if user reached page via GET (as by clicking a link or via redirect)
                if ($_SERVER["REQUEST_METHOD"] == "GET")
                    $rows = CS50::query("SELECT * FROM portfolios WHERE user_id = ?",

                    $positions = [];
                    foreach ($rows as $row)
                        $positions[] = [
                            "symbol" => $row["symbol"],

                    // render sell page with the right positions
                    render("sell.php", ["positions" => $positions, "title" => "Sell"]);        

Here is code for my view file:

   <form action="sell.php" method="get">
           <div class="form-group">

           <select class="form-control" name="symbol">
                <option disabled selected value="">Symbol</option>

              <?php foreach ($positions as $position): ?>
                 <option value = "$position["symbol"]" <$position["symbol"]> </option>
              <?php endforeach ?>


        <div class="form-group">
            <button class="btn btn-default" type="submit">Sell</button>

Figured it out. My first issue was in $rows query where I mistakenly asked for ID (which is an ID for portfolios) whereas I needed user_ID to get the portfolio for the user.

My second issue, I needed to change the text between the option tags to which I know is echo but which I don't totally understand yet.

  • To make this work, I also had to echo the variable after option value =.
    – Norcim133
    Jan 5 '16 at 23:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .