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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:26:35+00:00 2026-05-23T03:26:35+00:00

I have code to generate four cars from a DB with their photos: $l=$database->query(SELECT

  • 0

I have code to generate four cars from a DB with their photos:

$l=$database->query("SELECT car,brand,exactprice FROM $table ORDER BY rand() LIMIT 4");
$buffer="";
foreach($l as $l){
    $buffer.="<li><h3>{$l['car']}</h3><p>Price {$l['exactprice']}</p>";
    $k=$database->query("SELECT logo FROM logo WHERE brand='{$l['brand']}'");
    $buffer.="<img src='{$base_addr}/{$k[0]['logo']}'><br>";
}

That’s my current code. Can I rewrite my MySQL command so I would get logo from the logo with the first select I did?

Currently it takes 4.32 seconds to load this page.

  • 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-23T03:26:36+00:00Added an answer on May 23, 2026 at 3:26 am

    You didn’t supply what $table was, but either way you could use a JOIN on the brand column (assuming that this column is the appropriate foreign key).

    SELECT $table.car, $table.brand, $table.exactprice, logo.logo
    FROM $table JOIN logo ON $table.brand = logo.brand
    ORDER BY rand() LIMIT 4
    

    As far as the performance, you could look into creating indexes on the columns you use frequently and benchmarking by adding EXPLAIN in front of the query above.

    Some references to check out:

    • http://www.tizag.com/mysqlTutorial/mysqljoins.php
    • http://dev.mysql.com/doc/refman/5.0/en/create-index.html
    • http://dev.mysql.com/doc/refman/5.0/en/explain.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to generate a table listing brand/model/submodel/style for a group
I have code which generate table. You can see below the code: function createDynamicTable(tbody,
On my node.js server I have the following code: //Generate a token var token
I have the following code to generate two random numbers var attackRoll = Math.floor((Math.random()*6)+1);
I have the following code which will generate two pdf files containing plots to
I have following line of code to generate local notification after every 1 minute
I have the following piece of code that generate a jquerymobile-style button <a href=#
I use Acceleo in order to generate code with a model I have made.
I have created a UML diagram and generated a class by using Generate Code
I have a table with with four fileds as shown in figure Semester |

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.