0

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 :)

3
Contributors
8
Replies
42
Views
4 Years
Discussion Span
Last Post by pritaeas
0

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

0

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"]);
        }
    }       
0

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 :(

1

OH DO I FEEL SHEEPISH

Sorted, many thanks fo ryour input Dani:

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

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>';
    }
}
0

Make it easy on yourself:

Change the call from fetchAll in my class to:

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

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 :)

Edited by Squidge

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.