Jump to content

cant seem to get record in db


runnerjp

Recommended Posts

<?php $query = "SELECT fe.*, u.email, u.ID FROM forum_email as fe, users as u WHERE u.ID = fe.user_id AND fe.topic_id = " . $forumpostid . " AND fe.user_id != " . $id . " AND fe.mailed=1";
$res = @mysql_query($query) or die ("sendNotification query fails :".mysql_error());
echo $forumpostid; echo $id;
//nobody wants an email, stop now
if(mysql_num_rows($res)==0)
{
echo "no records returned";
        exit;
}?>

 

i have a record in

 

        forum_email

user_id topic_id mailed

1             484       1

 

but it keeps saying no reords returned...

 

this is the 1st time i have used a joining query hense an error is prob in there!

Link to comment
https://forums.phpfreaks.com/topic/132833-cant-seem-to-get-record-in-db/
Share on other sites

i've never used JOIN before either, but i believe you have to actually use the keyword for it to work...  :P

 

try:

$query = "SELECT fe.*, u.email, u.ID FROM forum_email as fe INNER JOIN users as u ON u.ID = fe.user_id WHERE fe.topic_id = " . $forumpostid . " AND fe.user_id != " . $id . " AND fe.mailed=1";

ok i have sorted that part

$query = "SELECT fe.*, u.email, u.ID FROM forum_email as fe INNER JOIN users as u ON u.ID = fe.user_id WHERE fe.topic_id = " . $forumpostid . "  AND fe.mailed=1";

 

i was thinking why do i need to get fe.user_id != " . $id . "  when im getting all the users under that topic

 

its just this part now

 

<?php

while(?? = mysql_fetch_assoc($res) ) {
        //define the receiver of the email
        $to = ??
        //define the subject of the email
        $subject = 'Test email';
        //define the message to be sent. Each line should be separated with \n
        $message = "im sending an email too myself.";
        //define the headers we want passed. Note that they are separated with \r\n
        $headers = "From: [email protected]\r\nReply-To: [email protected]";
        //send the email
        $mail_sent = @mail( $to, $subject, $message, $headers );
        //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
        echo $mail_sent ? "Mail sent" : "Mail failed";
}?

 

if i was to send an email in the loop what would my while(?? = mysql_fetch_assoc($res) ) be ?? and how would i get the users emails from the query above??

 

the emails are stored in the user table under email

ok i think i would need to do this

 

<?php $query = "SELECT fe.*, u.email, u.ID FROM forum_email as fe INNER JOIN users as u ON u.ID = fe.user_id WHERE fe.topic_id = " . $forumpostid . "  AND fe.mailed=1";
$res = @mysql_query($query) or die ("sendNotification query fails :".mysql_error());
echo $forumpostid; echo $id;
//nobody wants an email, stop now
if(mysql_num_rows($res)==0)
{
echo "no records returned";
        exit;
}

// ADDED CODE TO SEND EMAIL MESSAGES
$subj = 'Forum Updated';
$from = ' [your return information ] ';
$text = ' [your message text] ';

while ($row = mysql_fetch_assoc($res)) {
        extract ($row);
        if (!mail($email, $subj, $text, $from)) {
                echo "<br />MAIL FAILED FOR $email \n";
        }
}?>

 

$email --- houw would i get each users email form the query?

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.