Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Unanswered: Join 1 column from 1 table to another table

    I have a database in MySql named upload_data where there are 2 table named login consists of log_id, Username & password column & upload consists of upload_id, Title, Time column. Now what i want is that which user uploaded a data into the database table upload, if it is admin it will show the name admin, if it is other user then it will show the name of other users.

    Plz tell me what query i can apply.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by romeoasif View Post
    Plz tell me what query i can apply.
    show us the INSERT query that does the upload, and we'll show you how to add a CASE expression to do what you want
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2010
    Posts
    2

    my upload query

    <?php

    if($_FILES['upload_pic']['error'] == 0)
    {
    if(isset($_FILES['upload_pic']['tmp_name'])){
    copy ($_FILES['upload_pic']['tmp_name'], $_FILES['upload_pic']['name']);
    $uploadPath = $_FILES['upload_pic']['name'];
    echo "<br>Your Document: $uploadPath ";
    }
    }
    ?>

    ///// It will show upload result

    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("upload_data", $con);
    $time=date('Y-m-d H:i:s');
    $sql="INSERT INTO upload VALUES ('','$_POST[title]','$_SESSION[user]','$time')";
    if(isset($_FILES['upload_pic']['tmp_name'])){
    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    else {
    echo "1 record added";
    echo "<br>";
    $result = mysql_query("SELECT * from upload order by upload_id DESC limit 1");
    while($row = mysql_fetch_array($result))
    {
    echo "Your File Title is:".'&nbsp;'.$row['Title'].'<br>'."Uploaded Time:". $row['Time']. '<br/>';
    }
    }
    }
    mysql_close($con);
    //mysql_close($con)
    ?>

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by romeoasif View Post
    Now what i want is that which user uploaded a data into the database table upload, if it is admin it will show the name admin, if it is other user then it will show the name of other users.
    it appears you have no way to record which user uploaded the file

    you will have to add a "uploaded by" column to the upload table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •