php - How can I get a column from database based on the value of the column -
i wondering how can retrive item database using value of column, have database item column called sid, have different values based on should used for, have 1 item sid of "description" , sid value of "profile_view". how can 1 value of description using php pdo, code trying use:
try { $getsettings = $db->prepare("select * `profile_settings` profileid=?"); $getsettings->bindvalue(1, $profileid, pdo::param_str); $getsettings->execute(); $settingsdata = $getsettings->fetchall(pdo::fetch_assoc); foreach ($settingsdata $settingsrow) { $description = $settingsrow['sid']['description']; $profile_view = $settingsrow['sid']['profile_view']; } } catch (pdoexception $e) { }
$settingsrow['sid']
not associative array, it's string value of sid
column in row. need compare values you're looking for, value column.
foreach ($settingsdata $settingsrow) { $sid = $settingsrow['sid']; $value = $settingsrow['value']; // i'm assuming name of column relevant data if ($sid == 'description') { $description = $value; } elseif ($sid == 'profile_view') { $profile_view = $value; } }