If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Join 1 column from 1 table to another table

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-13-10, 03:20
romeoasif romeoasif is offline
Registered User
 
Join Date: Feb 2010
Posts: 2
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.
Reply With Quote
  #2 (permalink)  
Old 02-13-10, 06:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,085
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-14-10, 02:19
romeoasif romeoasif is offline
Registered User
 
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)
?>
Reply With Quote
  #4 (permalink)  
Old 02-14-10, 02:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,085
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On