I wanted to access two tables in mysql and want to use the fields in both tables. I used a innerjoin to match both tables, but wondering how to fetch the field in both tables, coz both tables are having same field name and different values.
Here is my query…
$query1 = mysql_query("SELECT facilitator.FacID, facilitator.email, assigned.email FROM facilitator INNER JOIN assigned ON facilitator.FacID = assigned.FacID WHERE assigned.email = '$stuemail' AND facilitator.active = '1'") or die($query."<br/><br/>".mysql_error());
while($line1=mysql_fetch_array($query1,MYSQL_ASSOC)){
$faci= $line1['FacID'];
$facemail = $line1['email'];
$stumail2 = $line1['email'];
.............code goes on..............
I want to fetch both emails field values but wondering how to do. I am sure what I have wrote for $stumail2 is wrong. Please help me.
You have a few options.
The first would be to assign a field-alias in MySQL:
The second, since you’re using
mysql_fetch_array(), is to access the fields by their index. Thefacilitator.emailfield has index1andassigned.emailhas index2, so you could use:Alternatively, by default, MySQL should be adding an incremental number (starting at
1) for each duplicate column name. So, you should be able to useemail1to access theassigned.emailcolumn: