Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

85
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!