Hello guys,

<?php 
					include 'dbconnect.php';
					echo 'under profile.php';
					$username=$_SESSION['username'];
					//I think i have to put a query here like "SELECT username FROM accntinfos WHERE username='$username'".  But confused since if I do there would be two queries
$query="SELECT userprofile.profpic FROM userprofile INNER JOIN accntinfos ON accntinfos.accntnum=userprofile.accntnum";
					$result=mysql_query($query, $DBconnect);
					$numrows=mysql_num_rows($result);
					
					
				?>

I have two tables on database ('TABLE1' which contains account informations of USERS, and 'TABLE2' which contains their personal informations). 'TABLE1' columns were 'account numbers' , 'username', and 'passwords', while 'TABLE2' columns were 'account numbers', 'firstname', 'lastname', ... and the rest of personal informations.

My aim is to find the 'lastname' (found on 'table2') of whoever has the account number matched on the 'TABLE1'. So what i did is I used INNER jOIN which you can see on the '$query' variable above.
--NOW WHAT I HAVE TO DO IS TO SEARCH THE USERNAME OF WHOEVER is LOGing IN THE SITE AND RETRIEVE HIS/HER LASTNAME--- but confused of how could to achieve it.

I have JOINED the two but I am stucked up to there. What should be the next step OR, maybe, what should I do before doing the JOIN?. And do I have to use multi query or something?.. pls help and thanks

You are almost done, just add column names in the select list you want to access. Your query is alright.

$query="SELECT userprofile.profpic, userprofile.lastname, userprofile.firstname FROM userprofile INNER JOIN accntinfos ON accntinfos.accntnum=userprofile.accntnum";

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.