Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

insert for cross compatibility

Question posted by: Deccypher (Newbie) on March 23rd, 2008 07:24 PM
sorry all i ever seam to do here is ask questions:(

but im really stuck on the best way to do this

what i have is 2 tables and im trying to make a 3rd table for compatibility

example
table 1
id
data
name
data1

table2
id
data
supplier
data2

what i want is a 3rd table

table3
id
table1 id
table2 id

thats easy but i want a php way of easy editing ti

main page
list all opetions in table 1 as links
Code: ( text )
  1. <?php
  2. //connect to mysql
  3. //change user and password to your mySQL name and password
  4. mysql_connect("localhost","username","password");
  5. //select which database you want to edit
  6. mysql_select_db("database");
  7. //select the table
  8. $result = mysql_query("select * from table1");
  9. //grab all the content
  10. while($r=mysql_fetch_array($result))
  11. {   
  12.    //the format is $variable = $r["nameofmysqlcolumn"];
  13.    //modify these to match your mysql table columns
  14. $id=$r["id"];
  15. $data=$r["data"];
  16. $name=$r["name"];
  17. $data1=$r["data1"];
  18.    //display the row
  19.    echo "<a href='main1.php?id=$id'>add compatibility for $name </a><br>";
  20. }
  21. ?>
the main1.php

on this one i want to show all the items in table 2 with check boxes
you can check the boxes and then when submit it adds an entry into table 3 for each cecked option

example

id table1_id table2_id
1,1,1
2,1,2
3,1,3
ect

where id is the table 3 id
table1_id is the id from table 1 ( passed through the link)
table2_id is the id from table 2 ( pulled down in this page)

its this page i am not sure how to do . i can do the pull down fine but doing the check boxes and the table insert i am unsure of

andy help will be greatly recived

2nd remark: Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Last edited by ronverdonk : March 24th, 2008 at 12:05 AM. Reason: code tags!!
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
dlite922's Avatar
dlite922
Site Addict
542 Posts
May 13th, 2008
04:29 AM
#2

Re: insert for cross compatibility
Quote:
Originally Posted by Deccypher
sorry all i ever seam to do here is ask questions:(

but im really stuck on the best way to do this

what i have is 2 tables and im trying to make a 3rd table for compatibility

example
table 1
id
data
name
data1

table2
id
data
supplier
data2

what i want is a 3rd table

table3
id
table1 id
table2 id

thats easy but i want a php way of easy editing ti

main page
list all opetions in table 1 as links
Code: ( text )
  1. <?php
  2. //connect to mysql
  3. //change user and password to your mySQL name and password
  4. mysql_connect("localhost","username","password");
  5. //select which database you want to edit
  6. mysql_select_db("database");
  7. //select the table
  8. $result = mysql_query("select * from table1");
  9. //grab all the content
  10. while($r=mysql_fetch_array($result))
  11. {   
  12.    //the format is $variable = $r["nameofmysqlcolumn"];
  13.    //modify these to match your mysql table columns
  14. $id=$r["id"];
  15. $data=$r["data"];
  16. $name=$r["name"];
  17. $data1=$r["data1"];
  18.    //display the row
  19.    echo "<a href='main1.php?id=$id'>add compatibility for $name </a><br>";
  20. }
  21. ?>
the main1.php

on this one i want to show all the items in table 2 with check boxes
you can check the boxes and then when submit it adds an entry into table 3 for each cecked option

example

id table1_id table2_id
1,1,1
2,1,2
3,1,3
ect

where id is the table 3 id
table1_id is the id from table 1 ( passed through the link)
table2_id is the id from table 2 ( pulled down in this page)

its this page i am not sure how to do . i can do the pull down fine but doing the check boxes and the table insert i am unsure of

andy help will be greatly recived

2nd remark: Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR


Sorry for the late response, some of use don't go digging in old posts. (old = past several days)

Perhaps we can help if we knew what those were and what you're trying to attempt instead of explaining at the programming level.

What does this system do? What are the names (or who) and what's the suppliers role (besides obviously supply), if any.

We might help you build a better way of doing things or help you finish.

Reply
dlite922's Avatar
dlite922
Site Addict
542 Posts
May 13th, 2008
04:46 AM
#3

Re: insert for cross compatibility
Also, I think what you're trying to do is build a many-to-many relationship, commonly solved by having a "link" table.

Example of a many to many relationship is for example

Table Actors
id
name
age

Table Movies
id
title
year


Movies can have *many* actors, and actors can have *many* movies. How you solve this is with a link table.

Table Starring
id
movie_id
actor_id

Example Data in Table this link table would look like this

1, 456, 234
2, 239, 290
3, 456, 120
4, 456, 290

The second pair of numbers in each row are foregin keys to the the first two tables of course.

Actor with id 290 has two movies, movie number 239 and 456. And Movie 456 also has actor 120 as another starring actor.

Hope that makes sense to you, and is related to your problem.

Reply
Reply
Not the answer you were looking for? Post your question . . .
183,969 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top PHP Forum Contributors