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 5989127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:03:26+00:00 2026-05-22T23:03:26+00:00

Ok. I have my query written finally for my php file (which will write

  • 0

Ok. I have my query written finally for my php file (which will write the query to a txt file). However, when I was testing the file earlier I apparently am excending the maximum execution time. I was using just one large query to do the work, but now I am wondering if it would be best to use multiple smaller queries. Would this cut down on the execution time?

If it would, then I have another question for all of you, how would I go about this? This is the bulk of my file:

// Query the database for data
$query = "SELECT 
  cards.card_id, 
  concat(cards.title, ' By Amy') AS cardTitle, 
  cards.meta_description,
  cards.description, 
  '' as Weight,
  '' as UPC,
  cards.seo_keywords,
  concat('http://www.amyadele.com/attachments//cards/',cards.card_id,'/',cards.card_image) AS ImageURL,
  card_import.artist,
  concat('ARTIST - ', card_import.artist) AS Brand,
  min(card_lookup_values.card_price) AS LowPrice,
 replace(lower(concat( 'http://www.amyadele.com/', pcat.seoname,'/',cat.seoname, '/', cards.seoname, '.htm' )),' ','+') AS link,
            concat(pcat.name,'>',cat.name) as Merchant,
 round(min(card_lookup_values.card_price), 2) AS newPrice,
 min(cast(lookup_details.value as signed)) as quantity

FROM
  cards
INNER JOIN card_cheapest on cards.card_id = card_cheapest.card_id
LEFT JOIN card_import on card_import.card_id = cards.card_id
INNER JOIN card_lookup_values on card_lookup_values.card_id = cards.card_id
INNER JOIN card_categories cc ON cards.card_id = cc.card_id AND cards.card_live = 'y' AND cards.active = 'y' AND cc.active = 'Y'
INNER JOIN categories cat ON cat.category_id = cc.category_id AND cat.active = 'Y'
INNER JOIN categories pcat ON cat.parent_category_id = pcat.category_id
INNER JOIN card_lookup_values as card_values ON cards.card_id = card_values.card_id
INNER JOIN lookup_details ON card_lookup_values.lookup_detail_id = lookup_details.lookup_detail_id

WHERE card_lookup_values.lookup_id = 7
GROUP BY
  cards.card_id
ORDER BY
  cards.card_id";


$result = mysql_query($query);


// Open file for writing
$myFile = "google.txt";
$fh = fopen($myFile, 'w') or die("can't open file");

// Loop through returned data and write (append) directly to file
fprintf($fh, "%-25s %-200 \n", "ID", "Name");

fprintf($fh, "\n");
while ($row = mysql_fetch_assoc($result)) {

 fprintf($fh, "%-25s %-200s \n", $row['card_id'], $row['cardTitle']);

 }

// Close out the file
fclose($fh);

echo "The file has been written sucessfully to googleproducts.txt. It will run again tomorrow at 12:00pm."
?>

As you can see I am pulling in $query to $results and then using that to insert it into $row. I guess my actual question (if possible), is how do I go about having $query, and $query2 and inserting $query2 into the same while statement?

  • 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-22T23:03:27+00:00Added an answer on May 22, 2026 at 11:03 pm

    Multiple queries, if anything, will just slow things down. It means compiling/executing multiple queries, so you end up with more overhead. Use explain on your query to see what indexes are (and aren’t) being used, and add more indexing where required. And in some cases, things will just naturally be slow. You are, after all, doing a 8-way join on 7 tables.

    Obvious places to check for index usage: each field in the where and join clauses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to rewrite a query written for mysql5 to mysql4.0 which doesn't support
I have a SQL query which is written in string and then executed using
I have a query, which when run from within phpMyAdmin, it works, however when
I have a query filter written in human readable language. I need to parse
I have a large query (not written by me, but I'm making some modifications).
I have written a LINQ to XML query that does what I want, but
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
I have following query written in HQL for Hibernate. ======================================================================== select new map(ret.retailerDesc as
I have written query, I wanted to know the effect of usage of IN
I have a query which has an Order By clause. The generated SQL from

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.