How to get value from the bank line and put in the checkbox

0

Good morning, I have a problem here, I created a line <p> which shows me the data from the database table id and the time . What I needed was to get this value and put it in the value of the checkbox so that I could send that information to another table in the form that would put the checkbox

<input type="checkbox" name="Hdisponivel[]" value="e colocava o valor da tabela aqui para poder selecionar que no caso seria o hora_de_segunda" />

My code:

<?php include("../php/agenda.php"); include("../php/alterar.php"); ?>


    <!DOCTYPE html>
    <html lang="pt-br" ng-app="AngularADM">

    <body ng-controller="TempoHorasP1">



        <div class="container">
            <div class="row">
                <h2 class="dourado texto-centro margin-top30 bold">Configuração da agenda online</h2>
            </div>

            <div class="row">

                <h3 class="texto-centro dourado">Agenda da 1º semana</h3>
                <hr />

                <div class="center-block">
                    <div class="row">

                        <div class="col-lg-3 texto-centro bloco-hora">
                            <p class="margin-top10">Segunda feira</p>
                            <hr />



                            <?php

    if($total > 0) {

        do {

?>


                                <div class="col-lg-4 texto-centro hora-banco">

                                    <p>
                                        <?=$linha['id']?>
                                    </p>

                                </div>

                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$linha['horas_de_segunda']?>
                                         <input type="checkbox" name="Hdisponivel[]" value="" />
                                    </p>

                                </div>


                                <?php

        }while($linha = mysqli_fetch_assoc($dados));

    }
?>

                        </div>

                        <div class="col-lg-3 texto-centro bloco-hora">
                            <p class="margin-top10">Terça feira</p>
                            <hr/>




                            <?php

    if($terc > 0) {

        do {

?>
                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$terLinha['id']?>
                                    </p>

                                </div>

                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$terLinha['horas_de_terca']?>
                                        <input type="checkbox" name="Hdisponivel[]" value="" />

                                    </p>

                                </div>


                                <?php

        }while($terLinha = mysqli_fetch_assoc($ter));

    }
?>

                            <input type="submit" />
                        </div>

                        <div class="col-lg-3 texto-centro bloco-hora">
                            <p class="margin-top10">Quarta feira</p>
                            <hr/>




                            <?php

    if($qua > 0) {

        do {

?>

                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$quarLinha['id']?>
                                    </p>

                                </div>

                                <div class="col-lg-4 texto-centro hora-banco">
                                    <p>
                                        <?=$quarLinha['horas_de_quarta']?>
                                        <input type="checkbox" name="Hdisponivel[]" value="" />
                                    </p>

                                </div>



    </body>


    </html>

agenda.php:

<?php
//require_once 'valida.php';
// definições de host, database, usuário e senha
include("conexao.php");

mysqli_select_db($link, $bd);

// cria a instrução SQL que vai selecionar os dados
$selecionar = "SELECT id, horas_de_segunda FROM horas_segunda";

// executa a query
$dados = mysqli_query($link, $selecionar) or die(mysqli_error($link));

// transforma os dados em um array
$linha = mysqli_fetch_assoc($dados);

// calcula quantos dados retornaram
$total = mysqli_num_rows($dados);


//segundo
$terca = "SELECT id, horas_de_terca FROM horas_terca";

$ter = mysqli_query($link, $terca) or die(mysqli_error($link));

$terLinha = mysqli_fetch_assoc($ter);

$terc = mysqli_num_rows($ter);


//terceiro

$quarta = "SELECT id, horas_de_quarta FROM horas_quarta";

$quar = mysqli_query($link, $quarta) or die (mysqli_error($link));

$quarLinha = mysqli_fetch_assoc($quar);

$qua = mysqli_num_rows($quar);

?>

As I could do, summarizing all this I need to get the value of mysqli_num_rows($quar); and put in <input type="checkbox" name="Hdisponivel[]" value="aqui dentro" />

Thank you

    
asked by anonymous 25.01.2017 / 14:53

2 answers

1

Just give%% of the variable within the echo field of value="" you want.

Example

<?php   $animal = 'gato';   ?>

<input type="text" value="<?= $animal ?>" />

The variable inside the " input " is the same as " <?= ?> "

Try this: <?php echo $animal; ?>

    
25.01.2017 / 15:15
0
<input type="checkbox" name="Hdisponivel[]" value="<?php echo myVar;?>" />

When you set the name to "[]" you are passing a variable of type array to the Post. This means you have to loop (usually a foreach) to get the value. If you want to directly access the value of the Post without the loop write like this:

<input type="checkbox" name="Hdisponivel" value="<?php echo myVar;?>" />
    
25.01.2017 / 18:13