Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:14:17+00:00 2026-05-30T21:14:17+00:00

Im building a simple album and track webapp but im getting into a pickle

  • 0

Im building a simple album and track webapp but im getting into a pickle with retrieving the correct information and making it efficient. I’ve got two tables – album has about 500 items and track with about 5000.

So I start off with a the normal while loop:

$albumQuery = "SELECT * FROM `album` ORDER BY album ASC";
$albumDatabase = mysql_query($albumQuery, $admin) or die(mysql_error()); 

while($albumRow = mysql_fetch_array($albumDatabase)){
    $list = "";
    $list.="build some html for showing later";

this is where I get into an efficency problem:

    $trackQuery = "SELECT track, album FROM `track` WHERE album = '{$album}' ORDER BY filename ASC";
    $trackDatabase = mysql_query($trackQuery, $admin) or die(mysql_error());

    while($trackRow = mysql_fetch_array($trackDatabase)){
        $list.="track html info";
    }

    $listarray[] = $list;
}

natcasesort($listarray);

I then run a foreach later in the body

foreach ($listarray as $v){
    $first_letter = strtoupper(mb_substr($v,9,1));
    if($tmp!==$first_letter){
        $tmp = $first_letter;
        echo '<div class="alphaHolder">'.$tmp.'</div>';
    }
    echo $v;
}

This works perfectly, apart from probably being possibly massively inefficent.

I can get it to regurgitate all the info in the right way and order.

As an experiment I placed of the second while loop outside the parent loop and stuck this info into its own array. Then ran this:

foreach($trackArray as $k => $v){
    if(in_array($v['album'], $albumRow)){
        $list.="track html info";
    }
}

But then I realized that every time it runs through the parent loop its rerunning the foreach over the 5000 items then doing the in_array 500 times. This obviously takes ages and normally crashes the browser. Leading me to the original nested while loop being slightly more efficient and convoluted.

I have started thinking that array_intersect might be the solution but I don’t want to bark up the wrong tree.

There’s probably too many loops and what have you going on but I need the natural sort and the alpha/numerical heading regurgitation.

Screenie: http://ink361.com/#/photos/133115598501394804_9688917

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:14:18+00:00Added an answer on May 30, 2026 at 9:14 pm

    You can first flip the array later check if the key exists. This will by much faster as its indexed searched unlike previous iterative search.

    $flipped_$albumRow = array_flip($albumRow);
    foreach($trackArray as $k => $v){
        if(isset($flipped_albumRow[$v['album']]))){ # <- line of interest.
            $list.="track html info";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building simple http status checker in C. I've got the network part done,
I am building a simple shop cart and I am getting the following array
Couple of friends and i will be building simple robot to track a white
I'm currently building a simple ecommerce site and have ran into an interesting problem.
I'm building a simple Contact Management app with Crud using AngularJS 1.0.0rc8. Getting a
I've enjoyed building out a couple simple applications on the GAE, but now I'm
I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing
I am building a simple Tac Tac Toe game in C++ but I get
I`m building simple app which shows information about most car brands. I have rootViewController
I'm building a simple project something like Twitter but very simple :) There are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.