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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:03:11+00:00 2026-06-09T21:03:11+00:00

tb1 —————– id | codetb1 —————– 1 | code1,code2 2 | code2,code3 tb2 —————–

  • 0

tb1

-----------------
id | codetb1
-----------------
1  | code1,code2
2  | code2,code3

tb2

-----------------
codetb2 | cost
-----------------
code1   | $20
code2   | $40
code3   | $60

save.php -> This is how I insert checkbox values to the database.

$codetb1 = $_POST['codetb1'];
var_dump($codetb1);

// Setting up a blank variable to be used in the coming loop.
$allStyles = "";
// For every checkbox value sent to the form.
foreach ($typeocodetb1fvisit as $style) {
    // Append the string with the current array element,
    // and then add a comma and a space at the end.
    $allStyles .= $style . ", ";
}
// Delete the last two characters from the string.
$allStyles = subs

tr($allStyles, 0, -2);

Result.php -> this is my connection and how I can get my result

$query="SELECT * FROM tb1, tb2 WHERE
  tb1.codetbl1 = tb2.codetbl2 AND
  tb1.id='$id'";

Hi all — your help is greatly appreciated. I have 2 databases (table 1 and table 2). I would like to have the 2 databases linked with one another. I am having trouble accomplishing this. For example, I tried explode but I couldnt make it work.

So How can I get rid of that comma from codetb1 and find a way to match with codetb2. So finally I can get cost. Any ideas?

  • 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-06-09T21:03:13+00:00Added an answer on June 9, 2026 at 9:03 pm

    Normalized Schema

    In my opinion, the only "real" answer to this question is to model the domain with a normalized schema. Specifically, we should never have one column storing more than exactly one piece of data. The term we use to describe your domain is that there is a many-to-many relationship, where one row in tb1 is related to many rows in tb2, and one row in tb2 can be related to many rows in tb1. The destination schema will look like this:

    tb1

    ---------
    id | ...
    ---------
    1  | ...
    2  | ...
    

    tb2

    ----------
    id | cost
    ----------
     1 | $20
     2 | $40
     3 | $60
    

    tb1_tb2

    -----------------
     tb1_id | tb2_id 
    -----------------
        1   |    1
        1   |    2
        2   |    2
        2   |    3
    

    Then, the way you select them depends on what you want. Here are some examples:

    The highest and lowest "cost" for each row in tbl1:

    SELECT tb1.name, MIN(tb2.cost) as low, MAX(tb2.cost) as high
    FROM tb1 
      JOIN tb1_tb2 ON tb1.id = tb2.tb1_id
      JOIN tb2_ON tb1_tb2.tb2_id = tb21.id
    GROUP BY tb1.name
    

    The sum of costs for rows in tb1:

    SELECT tb1.name, SUM(tb2.cost) as total
    FROM tb1 
      JOIN tb1_tb2 ON tb1.id = tb2.tb1_id
      JOIN tb2_ON tb1_tb2.tb2_id = tb21.id
    GROUP BY tb1.name
    

    The idea is to model each "thing" completely and distinctly; and the trick is to think of each relationship between a tb1 and a tb2 as a distinct "thing" (i.e. each one has a single row in tb1_tb2; the relationship is a full-class citizen in a normalized schema)

    Inserting is fairly straightforward once you think about the relationship as a distinct entity. If you have a tb1 and a tb2 you want to relate, simply add a tow to tb1_tb2 with their ids.

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

Sidebar

Related Questions

I have a series of TextBlock Controls, like this: <TextBox Name=tb1/> <TextBox Name=tb2/> <TextBox
SELECT tb1.booking_ref, tb1.investor, tb2.cost, tb3.product FROM tb1, tb3 LEFT JOIN tb2 ON tb1.booking_ref =
I have problem with this SQL query: (SELECT tb1.id,tb1.bdate,tb1.jumpCard,tb1.publicImage,tb1.lastlogin FROM users AS tb1, online
SELECT distinct source_IP, timestamp FROM tb1 , tb2 WHERE tb1.source_IP not in ( SELECT
I have this code to populate two textboxes: $(document).ready(function(){ $('.tb1').keyup(function(){ var content = $('.tb1').val();
When i click the Save Button in my page, it executes this protected void
I have written this scirpt: $(document).ready(function () { $('#tb1 li').hover(function () { var head
I want to execute an SQL query like: select 'tb1'.'f1','tb1'.'f2','tb2'.'f1' from 'tb1','tb2'; Now the
Well i got 3 tables: tb1: tb1_id PK tb1_name tb2: tb2_id PK tb1_id FK
I have the id of the TextBoxes as tb1, tb2, tb3 and the text

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.