There is a "username" field in two different table. Let say Table "a" has username, price, and title field. Table "b" has username, email_address, and name field.
I am building a webpage to display data of Table "a". At the same time, I am trying to link username field of Table "a" with email_address field of Table "b". So when my users clicks on one of username displayed on the page, an email window pops up and has corresponding email address of the username.
This is what I have used so far and never worked properly:
$query = mysql_query($sql_text);
$data = mysql_query("SELECT email_address FROM a WHERE username = '$username'");
// This is where I am trying to select appropriate email address for username
while ($myrow = mysql_fetch_array($query)) {
printf("<tr><td bgcolor=#ccccff><font face=arial size=2>%s</font></td><td nowrap bgcolor=#cccccc><font face=arial size=2>%s</font></td><td bgcolor=#ccccff><font face=arial size=2>%s</font></td><td bgcolor=#cccccc><font face=arial size=2>%s</font></td><td bgcolor=#ccccff><font face=arial size=2>%s</font></td><td bgcolor=#cccccc><font face=arial size=2>
<A href=\"mailto:$data[11]\">%s</A> // This is where actual link is created.
</font>
</td><td bgcolor=#ccccff><font face=arial size=2>%s</font></td></tr>\n", $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[6], $myrow[7], $myrow[8]
);
}
I have skipped some html coding inbetween. However, it is not working.
I think this is something to do with "while" statement. I am actually using while (--- mysql_fetch_array ---) to bring data from Table "a", but I am fetching anything from Table "b".
Can some please help me to resolve this link problem between tables?
I would greatly appreciate your help.
NY