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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:31:05+00:00 2026-05-13T05:31:05+00:00

I have a Sqlite database that has a table consisting of company information (Companies)

  • 0

I have a Sqlite database that has a table consisting of company information (Companies) and a table consisting of product information (Products). The Companies table id is Company_Name. It is joined with the Products table by Company_Name. For example, Company “A” can have many products associated with it, via inner join Companies on Company_Name = ProductID (ProductID consists of company names).

I am trying to display this information using a php while loop so that there will be a list of companies with their respective products. I cannot figure out how to do this. I can loop single records such as one company with one product, but I cannot list one company with multiple products. The following is what I am trying to achieve:

Company “A” – location CA
product 1, product 2, product 3

Company “C” – location CA
product 3, product 4, product 6

Company “F” – location CA
product 1, product 8

In this example the query would pull all companies in California (CA).

My code is as follows, but it doesn’t work:

//srchtext is the value in a HTML text box//
$txt = $_GET["srchtext"];
$dbstate = @$db->query("SELECT Company.Company_Name, Company.Company_City, Company.Company_State, Company.Company_Website, Company.Company_Service, Categories.Category_Name, Products.Product_Name FROM Company INNER JOIN Products On Company_Name = ProductID WHERE Company_State = '$txt'");
 while ($hmstate = $dbstate->fetchArray()){
echo "<ul>";
echo "<font id='srchclr'; color='#666666';>";
echo '<strong>'.$hmstate['Company_Name'].'</strong>'.'<br>'.$hmstate['Company_City'].','.$hmstate['Company_State'].'<br>'.
'<a href='.$hmstate['Company_Website'].'>'.$hmstate['Company_Website'].'</a>'.'<br>'.'<ul>'.
'<br>'.'<strong>Products or Services Provided by this Company:</strong>'.'<br>'.'<br>'.'<ul>'.$hmstate['Company_Service'].'</ul>';
echo "<br>";
echo "<strong>Company Product Category:</strong>";
echo "<br>";
echo "<br>";
  //Product loop//
  While ($hmstate = $dbstate->fetchArray()) {
  echo "<ul>";
  echo $hmstate['Product_Name'];
  echo "</ul>";
  }
}

Basically, my code gives me one company in California and lists all products associated with all companies in california:

Company “A” – location CA
product 1, product 2, product 3, product 3, product 4, product 6, product 1, product 8

I tried taking out the second php “while loop”, however I would get the following:

Company “A” – location CA
Product 1

Company “A” – location CA
Product 2

Company “A” – location CA
Product 3…

Although I am using Sqlite, if someone has an example in MySql or any other sql Db, that would really help as well. I think my issue is with the query and the php “while loop”.

  • 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-13T05:31:05+00:00Added an answer on May 13, 2026 at 5:31 am

    Your Product while-loop is fetching all products because you do not “break” when Company_Name changes.

    My PHP isn’t good but perhaps something like this:

    .
    .
    (Your company PHP code here)
    .
    .
    
    //Product loop//
    if ($hmstate = $dbstate->fetchArray()) {
    $fetch_okay = true;
    $Current_Company_name = $hmstate['Company_Name'];
    $same_Company = true;
    }
    
    While (fetch_okay && same_Company) {
      echo "<ul>";
      echo $hmstate['Product_Name'];
      echo "</ul>";
    
      $fetch_okay = false;
      $same_Company_Name = false;
      if ($hmstate = $dbstate->fetchArray()) {
        $fetch_okay = true;
        if ($hmstate['Company_Name'] = $current_Company_name) {
          $same_Company_Name = true;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app I have SQLite database that has one table with date rows
I have an sqlite database that has a blob column with blob data. I
I have a database table with a field that has values such as AAAA
I have a sqlite table that has amount field with NUMERIC(10,5) value(I know data
I have created an SQLite database which has a table which stores temperature values.
I have a SQLite database that contains a huge set of log messages. I
I have a pre-made SQLite database that I am downloading from the net via
I have a sqlite database which is opened in :memory: that needs to be
I have an app that creates a SQLite database ( with 24 records ),
I have a component that i want to store to an SQLite database. public

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.