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.

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.