# Basic php loop question

**URL:** https://forum.kirupa.com/t/basic-php-loop-question/195419
**Category:** Uncategorized
**Created:** [July 31, 2006, 4:44pm UTC](https://forum.kirupa.com/t/basic-php-loop-question/195419 "2006-07-31T16:44:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Increu](https://avatars.discourse-cdn.com/v4/letter/i/41988e/32.png) [@Increu](https://forum.kirupa.com/u/Increu)
#### Post date: [July 31, 2006, 4:44pm UTC](https://forum.kirupa.com/t/basic-php-loop-question/195419/1 "2006-07-31T16:44:50Z")

</div>

I was reading this  
[http://www.kirupa.com/web/mysql\_xml\_php.htm](http://www.kirupa.com/web/mysql_xml_php.htm)  
tutorial and there is a thing i didnt understand, wich is this single line inside the loop:

[SIZE=2][FONT=Courier New][COLOR=#0000bb]$row [/COLOR] [COLOR=#007700]= [/COLOR][COLOR=#0000bb] mysql\_fetch\_assoc[/COLOR]COLOR=#007700;

Why it uses the var $resultID ? Since what the loops change is the var $x  
that should be the var to take each line and make it an array, isnt it?  
this is the complete code  
[/COLOR][/FONT][/SIZE]

```php
                     <?php 
                    
                    header("Content-type: text/xml"); 
                    $host = "localhost";                     
                    $user = "root";                     
                    $pass = "";                     
                    $database = "test";                     
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 
                    
$query = "SELECT * FROM blog ORDER BY date DESC"; 
$resultID = mysql_query($query, $linkID) or die("Data not found."); 
                    
                    $xml_output = "<?xml version=\"1.0\"?>
"; 
                    $xml_output .= "<entries>
"; 
                    
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ 
                        $row = mysql_fetch_assoc($resultID);                     
                        $xml_output .= "	<entry>
"; 
$xml_output .= " <date>" . $row['date'] . "</date>
"; 
                            // Escaping illegal characters 
$row['text'] = str_replace("&", "&", $row['text']); 
$row['text'] = str_replace("<", "<", $row['text']); 
$row['text'] = str_replace(">", ">", $row['text']); 
$row['text'] = str_replace("\"", "&quot;", $row['text']); 
$xml_output .= " <text>" . $row['text'] . "</text>
"; 
                        $xml_output .= "	</entry>
"; 
                    } 
                    
                    $xml_output .= "</entries>"; 
                    
                    echo $xml_output;                     
                    
                                         ?> 
                    

```
