Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Array display problems

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Array display problems

Postby zmk » Thu Oct 25, 2012 2:18 am

hello,

I have a problem go on a two dimensional array. The code I wrote is as follows:

Code: Select all
for ($row = 2; $row < sizeof($data); $row++)
    {
        for($col = 0; $col < sizeof($data[$row]); $col++)
        {
            echo $data[$row][$col];
        }
        echo "<br>";
    }


And appear blanks, but if I change to:
Code: Select all
echo $data;


This Array writes the number of times the existing $ data. Someone can help me to show me the information in this array?
zmk
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Oct 25, 2012 2:12 am

Re: Array display problems

Postby egami » Thu Oct 25, 2012 7:57 am

before you do any of that..
make sure that the array looks like you want it to look...



echo '<pre>'; print_r($data); echo '</pre>';
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Array display problems

Postby jinijames » Mon Oct 29, 2012 3:23 am

$list = array();
$cat = array();
$query = mysqli_query($dbc,"SELECT id, parent_id, category FROM categories ORDER BY parent_id, category LIKE category ASC");
while($row = mysqli_fetch_assoc($query)){
$list[$row['id']] = array_merge($row, array('children' => array()));
}
mysqli_free_result($query);

foreach($list as $nodeId => &$node) {
if(!$node['parent_id'] || !array_key_exists($node['parent_id'], $list)){
$cat[] = &$node;
} else {
$list[$node['parent_id']]['children'][] = &$node;
}
}
unset($node);
unset($list);


Thanks,

hire php developer | hire magento developer
jinijames
New php-forum User
New php-forum User
 
Posts: 20
Joined: Fri Oct 19, 2012 4:32 am
Location: India


Return to PHP coding => General

Who is online

Users browsing this forum: freshnet and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron