2016-06-01 9 views
0

列の値を使用してデータベースから項目を取得する方法、sidという列を持つデータベース項目を持つ方法、私は "description"のsidと "profile_view"のsid値を持つ項目を持っています。私はPHPのPDOを使用して記述の値に1を得ることができ、これは私が使用しようとしていますコードでどのように :列の値に基づいてデータベースから列を取得する方法

try { 
    $GetSettings = $db->prepare("SELECT * FROM `profile_settings` WHERE profileId=?"); 
    $GetSettings->bindValue(1, $profileId, PDO::PARAM_STR); 
    $GetSettings->execute(); 
    $SettingsData = $GetSettings->fetchAll(PDO::FETCH_ASSOC); 

    foreach ($SettingsData as $SettingsRow) { 
     $description = $SettingsRow['sid']['description']; 
     $profile_view = $SettingsRow['sid']['profile_view']; 
    } 

} catch (PDOException $e) { 

} 

答えて

0

$SettingsRow['sid']は、それがsidの値を持つ文字列の連想配列ですされていませんその列の列。だからあなたはあなたが探している値とそれを比較し、次に別の列から値を取得する必要があります。

foreach ($SettingsData as $settingsRow) { 
    $sid = $SettingsRow['sid']; 
    $value = $SettingsRow['value']; // I'm just assuming this is the name of the column with the relevant data 
    if ($sid == 'description') { 
     $description = $value; 
    } elseif ($sid == 'profile_view') { 
     $profile_view = $value; 
    } 
} 
関連する問題