It’s hard to switch out of “normal” MySQL mode and start working with data stored in key/value format. The ‘wp_options’ table is an example of storing data in this key/value format. I was working on a cron job that required data from the ‘wp_options’ table. This is how I got where I needed to go:
1 2 3 4 5 6 7 8 9 10 11 12 |
$sql = "SELECT option_name, option_value FROM wp_options WHERE option_name IN ('key1','key2','key3')"; $result = mysql_query($sql); $data = array(); while(list($key, $value) = mysql_fetch_row($result)) { $data["$key"] = $value; } $key1value = $data['key1']; $key2value = $data['key2']; $key3value = $data['key3']; |
So if you want to retrieve specific key/value data in one pass with MySQL and then assign the results to PHP variables, this method might work for you:
You NEED to switch over to PDO or mysqli!
Agreed. Switch out these depreciated mysql extensions for whatever you are using.
The query used for selecting data from a key/value table is solid though.