mattm1712 Posted April 26, 2010 Share Posted April 26, 2010 i have been given this code which is wrong because it doent match my databases but i have never seen this join function before <?php $result4 = mysql_query("SELECT * FROM comments JOIN users on comments.submittedby=users.name WHERE comments.id=$t"); while($row = mysql_fetch_assoc($result4)); { $to = $row['email']; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } ?> in my database i have 2 tables one called 'users' which has titles. name email and pass then i have another one called comments with titles id comments submittedby and title. i have the varible t$ which will be equal to the id in the comments table, from this i want to selct the submittedby name in the commens table, this wi be the same as the name in the users table, then i want to echo out the email adress. can anyone help? Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted April 26, 2010 Share Posted April 26, 2010 Just needed to specify which fields you want. (since you have to designate from which table while using a join) SELECT comments.submittedby as submittedby, users.email as email FROM users JOIN comments on (comments.submittedby=users.name) WHERE comments.id=$t Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.