newbie question --Relate data between two tables
Posted: Fri Feb 24, 2006 11:56 am
feyd | Please use
My tables:
Table 'user' columns:
ID, name, quess1m, ques2m, --->ques20m
Table 'words' columns:
word, $mostsym
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi-I'm trying to relate data between two tables. I know some simple php/mysql, but I don't use it often enough to become an expert. I have a client who wants me to setup this for them. I've read up on 'joins', but I can't get it to work. The first table (users) contains 20 columns, each of which contain a certain word for each row. Each row corresponds to a userID. Table 2 (words)contains one word in each of 10 rows in a column (word) with a corresponding column (mostsym) containing containing a one-character code. Using my example below, what I'm trying to accomplish is if in the 'user' table any word that is in $row["ques1m"] matches any of the 10 words in the rows of the 'words' table, the corresponding letter in the 'mostsym' column of the 'words' table is echoed. Below is my feeble attempt and how the two tables are setup. Thanks for any assistance.
Here is as far as I got. Doesn't work.Code: Select all
$query = mysql_query("select * from words, users where users.ID='$ID'");
$result = $query;
while ($row = mysql_fetch_array($result)) {
echo (" " . $row["ques1m"] . " ");
if(" " . $row["ques1m"] . " = $word "){
echo $mostsym;}
}Table 'user' columns:
ID, name, quess1m, ques2m, --->ques20m
Table 'words' columns:
word, $mostsym
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]