Jump to content

checking if users made post?


runnerjp

Recommended Posts

ok like on here where if a user makes a post within the thread is shows the icon with a smilie face..

 

im looking to do that, there are 2 areas i would have to check

 

1st is if thread was started by them which i can do

 

echo $getthreads3[author] will get me topic auther via

 

<?php $getthreads = "Select * from forumtutorial_posts where parentid='0' and forum = '$forum' ORDER BY important ASC, lastrepliedto DESC $max"; 


    $getthreads2 = mysql_query($getthreads) or die("Could not get threads"); 

    while ($getthreads3 = mysql_fetch_array($getthreads2)) 
    {?> 

 

but i then store any posts made under that topic by posting the topic its posted under in parentid

my table looks like this

 

postid forum author   title post           parentid

  1      gen      user      test    what was said

  2      gen      user2    test      reply 2 post            1

  3      gen      user      test      reply to post          1

 

so basicly parent id shows which forum its posted under... so how could i check to see if the user has also replied to the thread to show the smilie face.... i hope this makes sence

Link to comment
https://forums.phpfreaks.com/topic/130504-checking-if-users-made-post/
Share on other sites

You could just use a SELECT statement, couldn't you?

 

You'd probably have to do a second query (in addition to the query you provided) like so:

<?php
$getthreads = "Select * from forumtutorial_posts where parentid='0' and forum = '$forum' ORDER BY important ASC, lastrepliedto DESC $max"; 

    $getthreads2 = mysql_query($getthreads) or die("Could not get threads");
//End of the code that you supplied

//inside the assumed while() loop for displaying the forum threads
while(....) {
	$query = mysql_query("SELECT `postid` FROM `forumtutorial_posts` WHERE `forum`='$forum' AND `author`='$author'");
	if(mysql_num_rows($query) != 0) {
		//Indicate that the user posted in this thread with an icon or such
	}
}

?>

 

NOTE:

With this method, I'm assuming that you provide the variable $author as some sort of session or cookie variable such as $author = $_SESSION['username'].

 

You might also have to modify this for it work properly with your script as I don't know how you structure your code. But this is essentially how you would do it.

could i somehow cut the code down so somethign like this

 

<?php
require_once '../settings.php';


$query = mysql_query("SELECT COUNT(postid) FROM `forumtutorial_posts` WHERE `postid`='255' OR 'parentid = '255' AND `author`='$author'");
$r = mysql_fetch_row($query);

   if($r[0] != 0) {
      echo 'yes you poster here';
   }
   ?>

 

 

 

adding a OR ... so basicly just checking under both collums for the post id and the username

ok i have gone for something like this

 

<?php
require_once '../settings.php';


$query = mysql_query("SELECT COUNT(postid) FROM forumtutorial_posts WHERE postid='262' OR parentid = '262' AND author='demo'");

   if($query != 0) {
      echo 'yes you poster here';
   }
   else
   {echo 'no';}
   ?>

 

but it always echos yes even if they arnt

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.