Here is a basic join code for two database tables, I want it to compare the two tables with a users email, it would have to be the current user logged on. How do i do so with php?

SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name

Recommended Answers

All 9 Replies

Member Avatar for iamthwee

Well how do you know what current user is logged on?

Are you storing their sessions id?

I have the users saved into a mysql database, so I know whose online. I am storing their session_id, but I want their email to be linbked which is stored as [email_of_user].

Member Avatar for iamthwee

So what part are you stuck on? Using the session_id to pull back their email addresses, or are you having trouble with the SQL query.

If it is the latter then you need to post up your table structure and how they are linked.

I'm new at this and dont really know how to say it but ill give it my best shot, I can get it to connect to the sql query, what i need is it to do somekthing like this,

SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.email_user_email=table_name2.email_user_email

I want it to know the user who is logged in and their email, and find that email in the other tables.

Okay I got my tables figured out,

`

 SELECT fgusers3.username, videos.videoname
    FROM fgusers3
    INNER JOIN videos
    ON fgusers3.email=videos.email
    ORDER BY fgusers3.username

`

now how do I have the email its looking to compare be the email of the user currently online. something like this,

session_start();

    $_Session['email_of_user'];


SELECT fgusers3.username, videos.videoname
FROM fgusers3
INNER JOIN videos
ON fgusers3.email=videos.email
ORDER BY fgusers3.username
Member Avatar for iamthwee

However you do it, it doesn't matter.

Somehow or another you need to obtain the userID and then from that get the email.

In fact using sessions might be a step in the wrong direction...

When the user logs on they will have to enter their username and password. Then this will be processed by the php POST function onbutton submit.

If the SQL query matches username and password you can immediately use the username variable to run another query to fetch their email.

Do you know enough about PHP to at least do this?

Sorry about this but I forgot to mention why I need the database tables to link, I have already created a login for when users visit my site, once these users are logged in they can upload videos, I have a table for the users when they login, and I have a table for when users upload videos, The table that uploads videos saves the video name given by the user, users email and the real videos name. What I want to do is allow the users to go to a account page and have it display what videos they have uploaded. So I need the code to find the email of the current user logged in and search that email in the other database table, and then bring up the results onto the webpage. So for instance I log in as Sample@gmail.com, and go to my account page, then a php form will search the database which holds all the video information and find which videos have Sample@gmail.com saved with them, and then display those results onto my account page.

Member Avatar for LastMitch

@garyjohnson

Sorry about this but I forgot to mention why I need the database tables to link, I have already created a login for when users visit my site, once these users are logged in they can upload videos, I have a table for the users when they login, and I have a table for when users upload videos, The table that uploads videos saves the video name given by the user, users email and the real videos name. What I want to do is allow the users to go to a account page and have it display what videos they have uploaded. So I need the code to find the email of the current user logged in and search that email in the other database table, and then bring up the results onto the webpage. So for instance I log in as Sample@gmail.com, and go to my account page, then a php form will search the database which holds all the video information and find which videos have Sample@gmail.com saved with them, and then display those results onto my account page.

What is the code? So far I been reading you are asking for a code but you haven't provide any code to work on? The code that you post above is not really helping. Plus I also notice you post other questions relating to this. This is very confusing. I'm not quite sure what you trying to accomplish here. It's like little info here and there.

Sorry I posted on the wrong forum and just didnt know what I was doing, disregard what I previously said, this is the code I have, I need to display the information from the database that holds my users account, I have this code which is suppose to display information from my database, but I want the code to display one section of the row which the code finds a match on, here is the code.

$username="xxxx";
$password="xxxx";
$database="xxxx";
$hostname="xxxx";
$user_email= $_SESSION['email_of_user'];
mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM videos WHERE email='$user_email'";
$result=mysql_query($query);
mysql_close();
echo "<b><center>Database Output</center></b><br><br>";
$vidoesname=mysql_result($result,$i,"email");
echo "<b>$videosname<br>";

I want the code to find a match in the database that is the same as the users email and display a different field which is on the same row of the users email. For instance my email is sample@gmail.com, and I have a video name saved into a table which has my email saved with it in the same row, I want the php code to display the videoname which is linked with the users email. as of now when I do this code it sats there is an error when I try to set the variable $videosname equal to mysql_result($result,$i,"email"); and I dont know why. This may or may not have anything to do with linking the databases, but I'm not sure.

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.