According to mysqli_fetch_assoc manual
Returns an associative array of strings representing the fetched row
in the result set, where each key in the array represents the name of
one of the result set's columns or NULL if there are no more rows in
resultset.
So after first iteration(using while) it's get empty.So you can't do second-iteration directly.
Solution: Create a variable first, and assign all data to that variable.Now use it as many time as you want