E
E
eellazy2016-02-24 15:48:42
PHP
eellazy, 2016-02-24 15:48:42

How to retrieve value from database?

Hello. There is such a thing

<select name="status" class="select_option input_form">
                    <option value="0">Статус</option>
                    <option value="1">Завершен</option>
                    <option value="2">Идут работы</option>
                </select>

it writes to me the values ​​0, 1 or 2 in the database. The output is the same, respectively. How to make it so that instead of the number 1, I would have a circle displayed. Or an inscription with a background

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Korchahin, 2016-02-24
@eellazy

Well, in theory, you can create an array of statuses (or any similar method):

$statuses = array(
    1 => 'Завершен',
    2 => 'Идут работы',
);

and when outputting, substitute the corresponding value
$status = ... // 1 или 2 значение из базы
echo $statuses[$status];
// Выведет 'Завершен' или 'Идут работы'

and following the example of any variations on this theme:
$statuses = array(
    1 => '<img src="кружочек">',
    2 => '<span class="надпись с фоном"></span>',
);

echo $statuses[$status];
// Соответственно либо надпись либо кружочек

The second option is right in the template:
<?php $status = (int)...; // 1 или 2 значение из базы ?>
<?php if ($status === 1) { ?>
    <img src="кружочек">
<?php } elseif ($status === 2) { ?>
    <span class="фон">Надпись</span>
<?php } ?>

S
Sergey Zelensky, 2016-02-24
@SergeyZelensky-Rostov

The first and appropriate question is why?

A
Andrey Fedorov, 2016-02-24
@aliencash

"1" is just a string. Accordingly, it can be any special character, such as html or acsii. For example & bull ; or \x248 (cp866).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question