0
I need it from the option selected on
<select>
, me check in the bank what is related to this option. I did this from way that follows below, but in part$p_id = $result['p_id'];
, no return, I have already used this array association code other times and it worked.I also need that all remain hidden until the moment of choice of
<option>
, after display what I did, with the records. I do not know the that is wrong, but I accept suggestions for solution and thank you from now on.<div class="form-group"> <div class="col-sm-3"> <label for="exampleInputEmail1">Cliente</label> <select class="form-control m-b-10" required="required" name="e_id" charset="utf-8"> <option>Selecione o cliente</option> <?php $select = "SELECT e_id, nome FROM pessoas"; $result = mysqli_query($conexao, $select); while($exibe = mysqli_fetch_assoc($result)){ $e_id = $exibe['e_id']; echo '<option charset="utf-8" value = '. $e_id . '>' . $exibe['nome'] . '</option>'; } mysqli_free_result($result); ?> </select> </div> </div> </form> <!--<button name="salvar" class="btn btn-success" onclick="showElement();">Pesquisar</button>--> <div id="dados" class="form-group" onload="hideElement();"> <?php if ($e_id <> '') { $select = "SELECT p_id FROM itens WHERE e_id = '$e_id'"; $result = mysqli_fetch_assoc(mysqli_query($conexao, $select)); $p_id = $result['p_id']; $select2 = "SELECT descricao where p_id = '$p_id'"; $resulta = mysqli_query($conexao, $select2); if (mysqli_num_rows($resulta) > 0){ echo '<table class="table table-hover" > <thead> <tr> <th>Descrição</th> </tr> </thead> <tbody> <tr>'; while($exibe = mysqli_fetch_assoc($resulta)){ $p_id = $exibe['p_id']; echo '<tr>'; echo '<td value = "">' . $exibe['descricao'] . '</td>'; } }else{ echo '<label for="exampleInputPassword1">Não há registros</label>'; } }else{ echo '<label for="exampleInputPassword1">Não há registros</label>'; } mysqli_free_result($result); mysqli_free_result($resulta); ?> </tr> </tbody> </table>
Your code doesn’t seem to make much sense (sorry if I didn’t understand it correctly), but you know how to differentiate language client-side of language server-side? PHP is server-side, but it seems that you tried to use it as if it were client-side, such as Javascript.
– Woss
You tried with: do{ //code.... } while($displays = mysqli_fetch_assoc($results));
– Marcelo Viana
explains your code from above. It’s all on one page only?
– user60252
I agree with @Andersoncarloswoss. I would even do it another way: Put a
form
withaction
for the same page and a trigger with jQuery or Javascript to give asubmit
at the eventchange
ofselect
. If you cannot have a "refresh" in your application, you can do (also) with ajax.– LipESprY