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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.