How to get value numbering ($no++) in foreach php?

i have 2 foreach with different query. The first foreach displays the customer name and transaction number.

Transaction number value in the first foreach is not from Database but from looping $no++.

How to get $no++ value from first foreach to store in second foreach based on customer name.

This Code :

$db = new mysqli("localhost","root","","test");

// Query Customer & Transaction No (First Foreach)
$sql_1 = "SELECT nama FROM pesan GROUP BY nama";
$result = $db->query($sql_1);

$no = 1;
foreach($result as $row){
echo $row['nama'].'<br>';
echo ' Transaction No ='.$no++.'<br>';

// Query Purchased product details (second Foreach)
$sql_2 = "SELECT product,nama FROM buy";
$result = $db->query($sql_2);

foreach($result as $row){
  echo $row['nama'].'<br>';
  echo 'Product Name=".$row["product'].'<br>';
  echo 'Transaction No ='.$no++.'<br>'; // transaction no is taken the value of $no++ from the foreach above based on customer name.

Result From First Foreach :

Transaction No =1
Transaction No =2

Result From Second Foreach :

  Product Name = TV 
  Transaction No = 1
  Product Name = radio 
  Transaction No = 2


Reliance Jio Brings New Prepaid Plan With 2.5GB Daily Data

a distributed, scalable load-testing tool built in go that leverages Google Cloud Functions