mattm1712 Posted April 26, 2010 Share Posted April 26, 2010 $t is difeined in my index page <?php $result4 = mysql_query("SELECT * FROM comments WHERE id=$t"); if($result4) { $row = mysql_fetch_assoc($result4); $name = $row['submittedby']; $query4 = mysql_query("SELECT * FROM user WHERE $name=name"); $row2 = mysql_fetch_assoc($query4); $email = $row2['email']; } $to = '$email'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> Link to comment https://forums.phpfreaks.com/topic/199822-would-this-work/ Share on other sites More sharing options...
taquitosensei Posted April 26, 2010 Share Posted April 26, 2010 it would kind of work. Something like this would work better. <?php $result4 = mysql_query("SELECT * FROM comments JOIN Users on Comments.Name=Users.NameWHERE Comments.id=$t"); while($row = mysql_fetch_assoc($result4)); { $to = $row['email']; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); } ?> Link to comment https://forums.phpfreaks.com/topic/199822-would-this-work/#findComment-1048882 Share on other sites More sharing options...
mattm1712 Posted April 26, 2010 Author Share Posted April 26, 2010 can u explAIN what this bit is doing so i can understand it a bit more? SELECT * FROM comments JOIN Users on Comments.Name=Users.NameWHERE Comments.id=$t Link to comment https://forums.phpfreaks.com/topic/199822-would-this-work/#findComment-1048885 Share on other sites More sharing options...
taquitosensei Posted April 26, 2010 Share Posted April 26, 2010 It's combining your 2 queries. It's selecting everything from comments and users where the name in comments = the name in users and Comments.id=$t let's say I have this table structure Comments comments name id Hi long time lurker, first time poster tom 1 Am I the only on here? tom 2 Users name id tom 1 This query select * from Comments JOIN Users on Comments.Name=Users.Name where Comments.id=1 would give you Comments.comment Hi long time lurker, first time poster Comments.name tom Comments.id 1 Users.name tom Users.id 1 Link to comment https://forums.phpfreaks.com/topic/199822-would-this-work/#findComment-1048913 Share on other sites More sharing options...
mattm1712 Posted April 26, 2010 Author Share Posted April 26, 2010 hi i sort of under stand but it doesnt seem to work i have changed it to SELECT * FROM comments JOIN users on comments.submittedby=users.nameWHERE comments.id=$t my tables are users ------------------------------------------------------ name | email | pass | location and comments ------------------------------------------------------ submittedby | title | id | comment i cant see y its wrong Link to comment https://forums.phpfreaks.com/topic/199822-would-this-work/#findComment-1048923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.