Jump to content

[SOLVED] linking tables


retro

Recommended Posts

Sorry if the answer is glaringly obvious here, but I am very new to MySQL and am basically learning as I go!

 

I have a MySQL4 database, which is standard MyISAM. 

 

In the table 'persons' I have fields ID, FirstName and LastName.

 

In the table 'orders' I have ID, customer, date and several Item fields (Item1, Item2 etc.)

 

I am using the following query:

 

$DelDate = $_POST["DelDate"];
$result = mysql_query ("SELECT ID,customer,Item1,Item2,Item3,Item4,Item5,Item6,Item7,Item8,Item9,Item10,date FROM orders WHERE DAYOFWEEK(date)=DAYOFWEEK(' . $DelDate . ')");
$total = mysql_num_rows($result);

 

I then use a while loop to echo the $row data into a table.  This works fine.

 

However, the data in 'customer' is a number, which matches 'ID' in 'persons'.  I want to display the first and last name instead, by looking these up in 'persons'.

 

My database knowledge comes from Access, so I know I'd do this with relationships.  How would I go about creating relationships on my current database, though?  I don't want to lose any data currently in the database.  I've seen people mention foreign keys, but from what I gather you can't have foreign keys with MyISAM.

 

How can I solve this?

 

Any help would be greatly appreciated.  Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/103875-solved-linking-tables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.