Jump to content

Reading normalized mysql database (key/value)


etrader

Recommended Posts

I have a normalized database in the form of

 

ID   user_id     key           value
1    3           first_name    Brian
2    3           last_name     Tardy
3    4           first_name    John
4    4           last_name     Wilson

 

 

What is the fastest way to capture these values within php? I want to perform a SELECT to catch the values for every user as

 

$result=mysql_query("SELECT * FROM users_data WHERE user_id = '$id'");
while($row=mysql_fetch_array($result)) {

here we process all data for a given user
and write it to text file as a single line

}

 

Since it is a long list (100K users with about 10M of rows in user_data), I am looking for the fastest and most reliable way to scan all the database.

?>

It is beyond me why you would store user information like that when you could just as easily create another field for every key you have listed there.  Doing that would cut your projected row count by at least 75% if not more..

 

But if you really want to get data out like that, then you would just use a query to filter by userid..

then use a foreach to assign the values to a multidimensional array.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.