Hi, I just had a quick question on printing results in an a certain array. // While row = mysql object while($row = mysql_fetch_object($result)) { // $cat = $row->cat; // $dog = $row->dog; // $mice = $row->mice; // Create a new entry in the array. $addresses[] = array( 'cat' => $row->cat, 'dog' => $row->dog, 'mice' => $row->mice ); } PHP: If I want the first rows 'cat' and 'mice'. Is this the correct way to write it: echo $addresses['0']['cat']['mice'];
They would each be their own hash within the array...... So..... echo $addresses[0]['cat']; echo $addresses[0]['mice']; PHP:
You can concatenate them if you want to output them both; although it is better to seperate with a comma for multilple lists. Thats if I misunderstoof you and you wanted to do it on one line E.G <?php #more efficient / quicker echo $addresses[0]['cat'], ":", $addresses[0]['mice']; ?> PHP: Or, what seems to be the more common way <?php # slower, but used more commonly echo $addresses[0]['cat'] . ":" . $addresses[0]['mice']; ?> PHP:
Thats the correct way. One more thing is that its not needed this much code to create the array $addresses. just use while($addresses[] = mysql_fetch_assoc($result));