A
A
Artyom Tsymbalyuk2016-06-13 13:17:40
PHP
Artyom Tsymbalyuk, 2016-06-13 13:17:40

How to default select another option in select?

Hello. Can you please tell me how to choose for select by default the option whose id is passed from the database?
i.e. there is a code

$old = mysql_fetch_array(mysql_query("SELECT title, cost, fr, btext, img, category FROM service WHERE id='".$iidd."'"));

<select name="category" value="<?php echo $old[5]; ?>">
              		<option value="1">Популярные</option>
              		<option value="2">YouTube</option>
              		<option value="3">Вконтакте</option>
              		<option value="4">Twitter</option>
              		<option value="5">Instagram</option>
              		<option value="6">Facebook</option>
              		<option value="7">Одноклассники</option>
              		<option value="8">Google+</option>
              		<option value="9">Periscope</option>
              		<option value="10">Другие услуги</option>
              	</select>

Let's say in SQL the line has the number 7 in the category, how to make it so that when the page is opened, by default the list had an option with value = 7

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-06-13
@lasmaster

For the required item, set the selected="selected" attribute

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question