0

I have an array containing about 400 10-20 character, single string number items. I want to query my database from this array in the most efficient way (on server load and load time) possible. Here is what I have currently but it takes about 4-6 seconds to load the page.

foreach(unserialize(mysqli_fetch_array(mysqli_query($database, "SELECT `array` FROM `users` WHERE `id` ='00000001'"))[0]) as $value) {
    $friend_id = mysqli_fetch_array(mysqli_query($database, "SELECT `id` FROM `users` WHERE `id` ='".$value."'"))[0];
    if(!empty($friend_id)){
        echo mysqli_fetch_array(mysqli_query($database, "SELECT 'username' FROM `users` WHERE `id` ='".$value."'"))[0] . "<br />";
    }
}
3
  • Are you storing serialized arrays in the database?
    – ironcito
    Commented Aug 10, 2013 at 1:32
  • Yes I am, should I do that or not?
    – Harry
    Commented Aug 10, 2013 at 1:48
  • 1
    No, you shouldn't. It creates problems like the one you're having, and it makes your database PHP-dependent.
    – ironcito
    Commented Aug 10, 2013 at 1:51

1 Answer 1

0

Look out for JOINs in SQL, e.g. at this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.