I have created two database tables, One which holds all of the users information, and another which holds the name of the videos they uploaded and who uploaded it. How do I get information from both tables?

Recommended Answers

All 4 Replies

Use a join, something like this:

SELECT * FROM users, videos WHERE videos.user_id = users.id

Okay so I have altered the code you gave me and I want it to join the other database with the email of the current user logged on,

session_start();
$email = $_SESSION['email_of_user'};

SELECT * FROM db_name, table_name WHERE table_name.email = $email

I want it to display a different field in the row that has the same email as the user. So I uploaded a video and named it Funny, that video name was saved into a database table that aslo saved my email. I want the code to display the video name, not the email once it is joined.

The SELECT * shows all columns, including the video name (if you have done it properly). It is hard to guide you without your database structure.

okay hopefully this helps,

    $con = mysql_connect("hostname","username","password");
    if (!$con){
      die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("radhalfs", $con);
    $name = mysql_real_escape_string($_FILES["file"]["name"]);
    $user = $_SESSION['email_of_user'];
    $videoname = mysql_real_escape_string($_POST['videoname']);
    $r = mysql_query("INSERT INTO `videos` SET `videoname` = '$videoname', 'email` = '$user', `name`= '$name'");
    if(mysql_affected_rows()){
        echo "1 record added";
    }else{
        echo "problem";
    }
}else{
    echo "Invalid file";
}

This is the code that inserts my information into the dataabase, called radhalfs, and it stores this information into a table named videos. It saves the videoname created by the user, user email and the real video file name.

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.