I want to show the table in my PHP page, my code is:
$query = "SELECT username FROM users_registration";
$result = pg_query($conn,$query);
$i=0;
while($row = pg_fetch_array($result))
{
$vm_array[$row[0]]=$row[0];
$i++;
}
username values in table are:
David amitra a David emilio Atul john rohit john
But my page shows only:
David amitra a emilio Atul john rohit
How to show all the missing data e.g. david, john?
The line
$vm_array[$row[0]]=$row[0];overwrites each occurrence of the value of$row[0], for example, ‘David’ and ‘john’, because you’re using the actual value as a hash key. So, you cannot have a value more than once in your “array”. Try$vm_array[] = $row[0];or$vm_array[$i] = $row[0];instead. But then you don’t have a hash, I know. It’s just to show the difference.