Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I tried many things but i just cant make the value of option an id from database and i cant write the option as date and title from database im doing this so far, any help would be appreciated.

<select name="agenda "size="10">
            <?php
            global $connection;
            $result = mysql_query("SELECT * FROM agenda where date > now() order by date", $connection);
            $i = 0;
            while ($row = mysql_fetch_array($result) && $i < 20)
                {
                $id = $row['id_agenda'];
                $date = $row['date'];
                $title = $row['title'];
                //here i would like to make an option with 
                //value = id_agenda and write the date_agenda and title_agenda
                //something like this
                //<option value="$row[$id]">$date $title</option>
                $i++;
                }
            ?>
            <option value="Google">meeting 2</option>
        </select>
share|improve this question
what you tried with an echo and the right quote marks will work fine – Dagon Jun 12 at 3:26
3  
There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future. – kaᵠ Jun 12 at 3:28
i tried that a lot of times but the option displayed is blank – user2476799 Jun 12 at 3:30
@user2476799 print_r($result); to check what data is pouring in – swapnesh Jun 12 at 3:56
All i had to do was to place $i < 20 in front of $row = fetch, i dont know the reason why but its working that way Thank you all – user2476799 Jun 12 at 5:26

2 Answers

Use:

echo "<option value=\"$id\">$date $title</option>";

share|improve this answer
while ($row = mysql_fetch_array($result)) {
    echo "<option value=\"$row[id_agenda]\">$row[date] $row[title]</option>";
}
share|improve this answer
i tried but it just shows a blank option – user2476799 Jun 12 at 3:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.