954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

mysql query inner join

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 containsaccount 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

bflack
Light Poster
38 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

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";
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

thanks

bflack
Light Poster
38 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: