# \[PHP/MySQL\] Looping through an array

**URL:** <https://forum.kirupa.com/t/php-mysql-looping-through-an-array/190047>\
**Category:** programming\
**Created:** [June 8, 2006, 7:27am UTC](https://forum.kirupa.com/t/php-mysql-looping-through-an-array/190047 "2006-06-08T07:27:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZephyrWest](https://avatars.discourse-cdn.com/v4/letter/z/87869e/32.png) [@ZephyrWest](https://forum.kirupa.com/u/ZephyrWest)\
**Post date:** [June 8, 2006, 7:27am UTC](https://forum.kirupa.com/t/php-mysql-looping-through-an-array/190047/1 "2006-06-08T07:27:15Z")

</div>

Hello, I’m having trouble deciphering what is going on in the following code:

```php
$query = "SELECT * FROM `tbl_users`";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "	<tr>
";
    echo "<td>$line</td>";
    foreach ($line as $col_value) { // $line is an array
       echo " <td>$col_value</td>
";
    }
    echo "	</tr>
";
}

```

I know what the inner foreach() loop is doing but I don’t see how the while() loops works. How is “$line = mysql\_fetch\_array($result, MYSQL\_ASSOC)” a condition? Wouldn’t it return the same value everytime if at all?

And another small question, when entering queries, is it necessary to suround the name of the table with the little tick marks (`) like in the first line? Or can I use single/double/no quotes?

Thanks a bunch. :azn:
