Hi All,

I am using pritaeas found here:
http://www.daniweb.com/web-development/php/code/430455/configurable-table-class

I am pulling in the data and my brain has taken a vacation.

I am using

$arr = $dsn->getRecord('memeber', array('user_id' => 2));

But cannot for the life of me pull the data out.

I get duplication as well from the data:

Array ( [0] => Array ( [user_id] => 2 [0] => 2 [loginName] => UserName [1] => UserName [password] => 30c2927b75d50c71550145ea7aebded6 [2] => 30c2927b75d50c71550145ea7aebded6 [email] => email@hotmail.co.uk [3] => email@hotmail.co.uk ) ) 

Can someone put me straight on this :)

Oh I had this problem with associative arrays in PHP myself recently. Let me see if I can find my remedy. Hold on.

Oh, nevermind. My code isn't very elegant at all. I used brute force:

    foreach ($objectinfo AS $key => $value)
    {
        // PHP has a nasty habit of storing numerical AND string keys for associative arrays
        if (is_numeric($key))
        {
            unset($objectinfo["$key"]);
        }
    }       

Dani,

Many thanks for that, it did start to help but its a multi :(

$tableConfig = array(
    'memeber' => array(
        'user_id' => PDO::PARAM_INT,
        'loginName' => PDO::PARAM_STR,
        'password' => PDO::PARAM_STR,
        'email' => PDO::PARAM_STR
        )    
);

My brain just wont kick in :(

OH DO I FEEL SHEEPISH

Sorted, many thanks fo ryour input Dani:

print $arr[0]['email'];

Ok, for stepping through :

foreach ($memeber[0] AS $key => $value) {
    if (is_numeric($key)) {
        unset($key, $value); // if the key is numerical unset $key and related $value
    } else {
        echo $key, ': ' . $value . '<br>';
    }
}

Make it easy on yourself:

Change the call from fetchAll in my class to:

while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
    $result[] = $row;
}

Many thanks pritaeas.

I have opted for the fetchAll, and used the following:

$staff = $dsn->getRecords('staff', array('live' => 0));

$result = count($staff); // ** Count the qty of first stage array
$x = 0;
while ($x < $result) {
    echo '<div class="post-container">';
    foreach ($staff[$x] AS $key => $value) { // ** Step into second stage array
        if (is_numeric($key)) {
            unset($key, $value);
        } else {

            if ($key != 'id' && $key != 'live' && $key != 'added') {
                if ($key == 'image') {
                    echo '<div class="post-thunb"><img src="photos/' . $value . '"/></div>';
                } else {
                    if ($key == 'drv_name') {
                        echo '<h1 class="post-title">' . $value . '</h1>';
                    } else {
                        echo '<div class="post-content">' . $value . '</div>';
                    }
                }
                unset($key, $value);
            }
        }
    }
    echo '</div>';
    $x++;
}
unset($dsn);

Works like a charm. So i have a massive thank you for your CRUD class :)

So i have a massive thank you for your CRUD class

Am glad it is of use.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.