Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

86
Visualizações
How to get multiple results in a php sql query

I have an API that checks against a SQL database for a part number, but there is a case where there are multiple part numbers for a SKU and when it gets that result it doesn't return anything in the UI, is there a way to choose one? From the results? For now I had this

 $squery ="SELECT part_no FROM parts where cb_master ='".$sku."'";
 $res = mysqli_query($connectiondb, $squery);
 $i=0;
 $row = mysqli_fetch_assoc($resultado);
 $part = $row['part_no'];
 if(is_array($row)){
 $check=0;
 while($check=1){
 $fixQuery = "SELECT no_item FROM orderdet WHERE no_order = $order AND no_item = $part[$i]";
 $arrayPart=mysqli_query( $connectiondb, $fixQuery);
 $i++;
 if($arrayPart!=''){
 $parte=$arrayPart;
 $check=1;
 return $part;
 }
 }
 }

I had a "limit 1" in the query but it didn't work, I don't know how to choose a single result (any of them would work), any ideas or help would be appreciated.

over 2 years ago · Carlos Garzón Colorado
1 Respostas
Responde à pergunta

0

If you only need to retrieve one of the records when multiple matches exist, you can use LIMIT 1 in the query and retrieve the first result with mysqli_fetch_assoc() . However, there are several problems in your code: you're using different variables ( $res and $resultado ), the while($check=1) condition performs an assignment instead of a comparison, and $part is not an array but a single value.

If there are indeed multiple part_no results, you should iterate through all of them using mysqli_fetch_assoc() within a while loop and decide which one to use based on your business logic. The problem seems to lie more in the handling of the results than in the SQL query itself.

3 months ago · Ruben Alexander Serrano Porras Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda