[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

making a notify me of replies code

Posted on 2008-11-13
3
Medium Priority
?
328 Views
Last Modified: 2012-05-05
ok i have made my own forum and im currently creating a notify me of replies part for my forum...

i have come up with the idea of this..

Make a forum_email table..... this has:
user_id
topic_id
mailed (enum y/n)

If a user wants an email when this thread is replied to, insert a row and set mailed to default = n.

Now, when someone makes a reply to this topic, do...

$query = "SELECT fe.*, u.email, u.name FROM forum_email as fe
LEFT JOIN users as u on u.user_id = fe.user_id
WHERE topic_id = '".$this_topic_id."' AND fe.user_id != '".$thepostinguser."' AND mailed='n'";
$res = @mysql_query($query,$link) or die ("sendNotification query fails :".mysql_error());

//nobody wants an email, stop now
if(count($user_id) == 0):
return;
endif;

foreach($user_id as $value) {
send emails
}

//set emailed to 'y' so that they don't get numerous emails... set it back to 'n' when they view this topic
$query_noted = "UPDATE forum_email SET mailed='y' WHERE topic_id = '".$this_topic_topic_id."'";



the problem is if the user is vreating the post and the post id is auto inc how can i get the topic id if its not yet created :@S
0
Comment
Question by:runnerjp
3 Comments
 
LVL 15

Expert Comment

by:MMDeveloper
ID: 22949878
you can get the ID of the last insert by using the mysql_insert_id() function.. so... just run the INSERT to create the topic and THEN run

$newPostID = mysql_insert_id();

and now $newPostID has the ID of the newly created topic. You'll just have to run your "email me of replies" code after the topic creation.
0
 

Author Comment

by:runnerjp
ID: 22951931
how would i do this

i tried the code below but it didnt work
		$insertpost = "INSERT INTO forumtutorial_posts(forum,author,title,post,showtime,realtime,lastrepliedto,lastposter) values('$forum','$username','$theSubject','$thePost','$thedate','$thedate','$thedate','$username')";
												mysql_query($insertpost) or die("Could not insert post"); //insert post
												//$insertemail = "INSERT INTO forum_email(user_id,topic_id,mailed) values('$id','$forumpostid','1')";
												//mysql_query($insertemail) or die("Could not insert email"); //insert  email
												$updatepost = "UPDATE `users` SET `post_count`=`post_count`+'1' WHERE `Username`='$username'";
												mysql_query($updatepost) or die("Could not update post");
												$newPostID = mysql_insert_id($insertpost);
												echo $newPostID;
												//header("Location: http://www.runningprofiles.com/members/index.php?page=forum&forum=$forum");
												exit;

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 22953341
See if this helps... ~Ray

SP: if the query fails to insert, $xyz == FALSE
$insertpost = "INSERT INTO ...";
$xyz = mysql_query($insertpost) or die("Could not insert post"); // RESOURCE ID IS IN $xyz
$newPostID = mysql_insert_id($xyz);
echo $newPostID;

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question