Show in select database results

Asked

Viewed 51 times

0

I’ve researched this before and I could never get a code that works. When I put the code on, nothing gets a single option.

I wanted a code that could see the data in a select

Code that I’m using:

Serviço: <br>
<select name='servico' id='servico'>
<option>Selecionar Serviço</option>
<?php 
$sql_p= "SELECT nome_prod FROM produtos";
$query=mysqli_query($ligacao,$sql_p);
$rows=array();
while($row=mysqli_fetch_assoc($query)){
    $rows[]=$row;
    echo "<option value=".$rows['nome_prod'].">".$rows['nome_prod']." 
</option>";
}?>
</select>
  • Have you tried using the mysqli_fetch_array ?

  • I haven’t used the mysqli_fetch_array

  • mine is like the bottom one now, but there’s nothing in it

  • the mysqli_fetch_array is not the same thing as the mysqli_fetch_assoc?

  • The difference between the two is basically in the indexing of the array.

1 answer

0

Use the mysqli_fetch_object direct to display the results in object format.

Serviço: <br>
<select name='servico' id='servico'>
<option>Selecionar Serviço</option>
<?php 
$sql_p= "SELECT nome_prod FROM produtos";
$query=mysqli_query($ligacao,$sql_p) or die(mysqli_error($ligacao);
while($row=mysqli_fetch_object($query)){
    echo "<option value=".$row->nome_prod.">".$row->nome_prod."</option>";
}?>
</select>
  • I can’t. I don’t know why I don’t give anything away. Image:https://imgur.com/a/tZLUwfm

  • add the error in the query $query=mysqli_query($ligacao,$sql_p) or die(mysqli_error($ligacao)); and see if there are any mistakes

  • https://imgur.com/a/tZLUwfm gives this

  • try the way I put it in the answer

  • because of the or die(mysqli_error($ligacao)) the rest I had when I put in comment what had left back, but still the same thing does not give

  • Then see if you are printing an error within select or Inspecione the code to find it

  • I can send the whole code to you

  • Probably something is wrong with your database query. Try running your query directly and see what returns. We just need the bug, not the whole code

  • I’m saying I can send it to help me find out, that this is a data entry

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.