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
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";

Link to comment
Share on other sites

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: n0144040@ntu.ac.uk\r\nReply-To: webmaster@example.com";
        //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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.