On Feb 28, 2008, at 1:29 PM, Rob Wultsch wrote:
On Thu, Feb 28, 2008 at 10:59 AM, Jason Pruim <[EMAIL PROTECTED]>
wrote:
Hi Everyone,
I am attempting to write a PHP application that reads info from a
MySQL database, and I'm wondering if I can set up a column in one
table that gets it's info from a field in another table
automatically?
Ie:
Table1:
field1
field2
field3
Table2:
field4
field5
field6 = field1
Does that make sense? Would that be a join? Or maybe a primary key?
I'm new to MySQL programming so RTFM's are appreciated as long as "M"
is defined :)
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
[EMAIL PROTECTED]
Tip for future questions:
Figure out the simplest way to present the question and include the
SQL to create the relevant tables.
Next explain what you want, any non working sql you have, and lastly
give an example result of correct output.
Hi Rob, I will do this in the future, thank you.
And to that end:
CREATE TABLE `current` (
`customerName` varchar(30) default NULL,
`customerBusiness` varchar(30) default NULL,
`loginName` varchar(30) default NULL,
`loginPassword` varchar(32) default NULL,
`tableName` varchar(20) default NULL,
`email` varchar(50) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `adminAll` (
`dispalyTableName` varchar(20) default NULL,
`adminLevel` int(10) default NULL,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=latin1
What I want, is displayTableName on table adminAll to grab it's info
from tableName in current. Does that make more sense?
Example:
So lets say I have two tables:
CREATE TABLE `t1` (
`t1_id` int(10) NOT NULL auto_increment,
`t1_data` varchar(255) NOT NULL default '',
`t2_id` int(10) NOT NULL default '0',
PRIMARY KEY (`t1_id`),
KEY `t2_id` (`t2_id`)
);
CREATE TABLE `t2` (
`t2_id` int(10) NOT NULL auto_increment,
`t2_data` varchar(255) NOT NULL default '',
PRIMARY KEY (`t2_id`)
);
I want to show all the information in t1 and any information in t2
where the t1.t2_id is equal to t2.t2_id.
Output should be like:
t1_id,
t1_data,
t2_data
*Answer*
I really am not sure what you were asking, but take a look at this
query for the table structure above.
SELECT t1_id, t1_data, t2_data
FROM t1
INNER JOIN t2 USING(t2_id)
*Better answer*
Go buy an introductory book on sql. Read through a couple examples.
( http://www.w3schools.com/sql/default.asp is also very good)
I have been working with MySQL in various degrees for the past few
years, I've just never needed to grab info from another table and
import it to a different table.
My Main area of expertise is in web design (mostly HTML and CSS) and
some PHP.
From the above question you probably do not know enough to tread water
in the very excellent MySQL manual.
From my original post:
"Does that make sense? Would that be a join? Or maybe a primary key?
I'm new to MySQL programming so RTFM's are appreciated as long as "M"
is defined :)"
--
Rob Wultsch
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
[EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]