Jump to content

would this work?


mattm1712

Recommended Posts

 

$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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.