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

  • Home
  • SEARCH
  • 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 6197719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:52:19+00:00 2026-05-24T03:52:19+00:00

I’m sure this has been discussed many times before, but for whatever reason I

  • 0

I’m sure this has been discussed many times before, but for whatever reason I didn’t find anything (could be no coffee).

As a design question here’s the idea.

One (remote) database looks something like this
id|timestamp|log_entry|task_id

These are fetched to a PHP/Codeigniter portal and mapped to a local database
task_id|name|...

Now, parsing through the remote data I need to (among other things) get the name associated with each row. The simple way would be to loop through the result, and in each iteration do a lookup (id -> name). But this will generate a lot of DB calls. The other way I see it is to pre-fetch all id-name pairs into an array, and then use that for lookup.

For this specific project I’m not expecting performance to be an issue either way. But which would be the most efficient way to do this?

EDIT: Pseudo code

<?php
// ---------- Multiple queries example ------
$log_result = mysql_query('SELECT id, task_id, log_entry, timestamp FROM remote_db WHERE date=X');

foreach ($log_result as $log_row)
{
    // Get task name for row
    $task_name = mysql_query("SELECT name FROM local_db WHERE id={$log_row['task_id']}");

    // Process this row ...
    echo "Proccesed {$task_name} which occured at {$log_row['timestamp']}";
}

// ---------- Array example -----------------
$task_lookup = mysql_query('SELECT id, name FROM local_db');
$log_result = mysql_query('SELECT id, task_id, log_entry, timestamp FROM remote_db WHERE date=X');

foreach ($log_result as $log_row)
{
    // Get task name for row
    // assume task_lookup[] = array(id => name)
    $task_name = $task_lookup[$log_row['task_id']];

    // Process this row ...
    echo "Proccesed {$task_name} which occured at {$log_row['timestamp']}";
}
?>
  • 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-24T03:52:19+00:00Added an answer on May 24, 2026 at 3:52 am

    If you need all the information anyway then certainly selecting it once and looping over what you need (particularly since the database is remote and the latency of many calls will add up).

    Edit: Looking at the pseudo code:
    You could use the array of ids from the remote DB to narrow the results grabbed from the local db. Something like:

    $log_result = mysql_query('SELECT id, task_id, log_entry, timestamp FROM remote_db WHERE date=X');
    $task_lookup = mysql_query('SELECT id, name FROM local_db WHERE id IN taskIdsFromLogQuery');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.