View Full Version : Pulling thread title from query
Boofo
03-07-2003, 03:05 AM
What I'm trying to do with the code below is pull both the post title (if there is one) and the thread title from the getlastposts query. What I want it to do is is show "Re: threadtitle" is there is no post title. Can someone please tell me what I am doing wrong?
$totalposts=$userinfo[posts];
if ($totalposts!=0 or $userinfo[lastpost]!=0) {
$getlastposts=$DB_site->query("SELECT thread.title,thread.threadid,thread.forumid,post.t itle,postid,post.dateline FROM post,thread WHERE thread.threadid=post.threadid AND post.userid=$userinfo[userid] AND post.visible=1 ORDER BY post.dateline DESC");
$postctr=0;
$latestposts="";
while ($getlastpost=$DB_site->fetch_array($getlastposts)) {
$getperms=getpermissions($getlastpost[forumid],$bbuserinfo[userid],$bbuserinfo[usergroupid]);
if ($getperms[canview]==1) {
$postdate=vbdate($dateformat,$getlastpost[dateline]);
$posttime=vbdate($timeformat,$getlastpost[dateline]);
$posttitle=$getlastpost[title];
$posttitle=censortext($posttitle);
$posttitle=htmlspecialchars($posttitle);
$posttitle=preg_replace("/(\[)(you)(])/siU", $bbuserinfo[username], $posttitle);
$threadtitle=$getlastpost[title];
$threadtitle=censortext($threadtitle);
$threadtitle=htmlspecialchars($threadtitle);
$threadtitle=preg_replace("/(\[)(you)(])/siU", $bbuserinfo[username], $threadtitle);
$posturl="showthread.php?postid=$getlastpost[postid]#post$getlastpost[postid]";
$postctr++;
if ($postctr==1){
$lastpostdate=$postdate;
$lastposttime=$posttime;
$lastposttitle=$posttitle;
$lastposturl=$posturl;
}
eval("\$latestposts .= \"".gettemplate("getinfo_latestposts")."\";");
then you'd do something like this
$totalposts=$userinfo[posts];
if ($totalposts!=0 or $userinfo[lastpost]!=0) {
$getlastposts=$DB_site->query("SELECT thread.title,thread.threadid,thread.forumid,post.t itle,postid,post.dateline FROM post,thread WHERE thread.threadid=post.threadid AND post.userid=$userinfo[userid] AND post.visible=1 ORDER BY post.dateline DESC");
$postctr=0;
$latestposts="";
while ($getlastpost=$DB_site->fetch_array($getlastposts)) {
$getperms=getpermissions($getlastpost[forumid],$bbuserinfo[userid],$bbuserinfo[usergroupid]);
if ($getperms[canview]==1) {
$postdate=vbdate($dateformat,$getlastpost[dateline]);
$posttime=vbdate($timeformat,$getlastpost[dateline]);
$posttitle=$getlastpost[title];
$posttitle=censortext($posttitle);
$posttitle=htmlspecialchars($posttitle);
$posttitle=preg_replace("/(\[)(you)(])/siU", $bbuserinfo[username], $posttitle);
$threadtitle=$getlastpost[title];
$threadtitle=censortext($threadtitle);
$threadtitle=htmlspecialchars($threadtitle);
$threadtitle=preg_replace("/(\[)(you)(])/siU", $bbuserinfo[username], $threadtitle);
$posturl="showthread.php?postid=$getlastpost[postid]#post$getlastpost[postid]";
if ($posttitle == "") { //only part i changed
$posttitle = "Re: $threadtitle";//
}//
$postctr++;
if ($postctr==1){
$lastpostdate=$postdate;
$lastposttime=$posttime;
$lastposttitle=$posttitle;
$lastposturl=$posturl;
}
eval("\$latestposts .= \"".gettemplate
("getinfo_latestposts")."\";");
Boofo
03-07-2003, 04:22 AM
Here's what i want to do. I want it to loist like this:
posttitle (Thread: threadtitle)
Will this do this? And how can I get the actual number of posts if a user has less than 10 posts?
loist?
anyways, so if there is no post title you want the post title to be "Re: $threadtitle" where $threadtitle is the title of the thread?
Boofo
03-07-2003, 04:25 AM
Here's the code I am working with now. I took out all the other stuff because it wasn't working.
$totalposts=$userinfo[posts];
if ($totalposts!=0 or $userinfo[lastpost]!=0) {
$getlastposts=$DB_site->query("SELECT thread.title,thread.threadid,thread.forumid,postid ,post.dateline FROM post,thread WHERE thread.threadid=post.threadid AND post.userid=$userinfo[userid] AND post.visible=1 ORDER BY post.dateline DESC");
$postctr=0;
$latestposts="";
while ($getlastpost=$DB_site->fetch_array($getlastposts)) {
$getperms=getpermissions($getlastpost[forumid],$bbuserinfo[userid],$bbuserinfo[usergroupid]);
if ($getperms[canview]==1) {
$postdate=vbdate($dateformat,$getlastpost[dateline]);
$posttime=vbdate($timeformat,$getlastpost[dateline]);
$posttitle=$getlastpost[title];
$posttitle=censortext($posttitle);
$posttitle=htmlspecialchars($posttitle);
$posttitle=preg_replace("/(\[)(you)(])/siU", $bbuserinfo[username], $posttitle);
$posturl="showthread.php?postid=$getlastpost[postid]#post$getlastpost[postid]";
if ($posttitle == "") { //only part i changed
$posttitle = "Re: $threadtitle";//
}//
$postctr++;
if ($postctr==1){
$lastpostdate=$postdate;
$lastposttime=$posttime;
$lastposttitle=$posttitle;
$lastposturl=$posturl;
}
eval("\$latestposts .= \"".gettemplate("getinfo_latestposts")."\";");
if ($postctr==$showposts) {
break;
}
}
}
} else {
eval("\$latestposts .= \"".gettemplate("getinfo_latestpostsnone")."\";");
Boofo
03-07-2003, 04:27 AM
Originally posted by mr e
loist?
anyways, so if there is no post title you want the post title to be "Re: $threadtitle" where $threadtitle is the title of the thread?
Yes, sir. I want to have the thtreadtitle after it on all of them, too. I thought I had it once but I got messed up somewhere. ;)
well i look at the query and you aren't getting the post title, you have thread.title so your $posttitle=$getlastpost[title] is really your thread title
is this out of a php file or did you modify it?
Boofo
03-07-2003, 04:30 AM
Originally posted by mr e
loist?
loist=look
LOL My damned keyboard can't spell.
so you want the post's title AND the thread's title?
Boofo
03-07-2003, 04:31 AM
Originally posted by mr e
well i look at the query and you aren't getting the post title, you have thread.title so your $posttitle=$getlastpost[title] is really your thread title
is this out of a php file or did you modify it?
It's from an older hack I am updating for my site. How do we get the post title out of that query?
Boofo
03-07-2003, 04:33 AM
Originally posted by mr e
so you want the post's title AND the thread's title?
LOL We keep cross-posting here.
Yes, I want to get them both. :)
LOL, ya we are cross posting
ok try this, it's late so it might not be perfect and if it's not i'll fix it tomorrow cuz my bed's calling me :)
$totalposts=$userinfo[posts];
if ($totalposts!=0 or $userinfo[lastpost]!=0) {
$getlastposts=$DB_site->query("SELECT thread.title AS threadtitle,thread.threadid,thread.forumid,post.ti tle AS posttitle,post.postid,post.dateline,post.userid,po st.visible FROM thread,post WHERE thread.threadid=post.threadid AND post.userid=$userinfo[userid] AND post.visible=1 ORDER BY post.dateline DESC");
$postctr=0;
$latestposts="";
while ($getlastpost=$DB_site->fetch_array($getlastposts)) {
$getperms=getpermissions($getlastpost[forumid],$bbuserinfo[userid],$bbuserinfo[usergroupid]);
if ($getperms[canview]==1) {
$postdate=vbdate($dateformat,$getlastpost[dateline]);
$posttime=vbdate($timeformat,$getlastpost[dateline]);
$posttitle=$getlastpost[posttitle]."(Thread: ".$threadtitle.")";
$posttitle=censortext($posttitle);
$posttitle=htmlspecialchars($posttitle);
$posttitle=preg_replace("/(\[)(you)(])/siU", $bbuserinfo[username], $posttitle);
$posturl="showthread.php?postid=$getlastpost[postid]#post$getlastpost[postid]"; ///////// <- Not sure what this is supposed to be, what's with the # sign?
$postctr++;
if ($postctr==1){
$lastpostdate=$postdate;
$lastposttime=$posttime;
$lastposttitle=$posttitle;
$lastposturl=$posturl;
}
eval("\$latestposts .= \"".gettemplate("getinfo_latestposts")."\";");
if ($postctr==$showposts) {
break;
}
}
}
} else {
eval("\$latestposts .= \"".gettemplate("getinfo_latestpostsnone")."\";");
Boofo
03-07-2003, 06:56 AM
Thank you, sir. Works great. With just a few tweaks I got it running smooth. I owe you one. ;)
oh cool :D i guess i can code when im asleep ;)
Falkware
05-10-2003, 10:06 PM
How do you then get this into postbit template to display the RE: threadtitle on all replies after the initial threadpost? I've been looking for something like this as well to avoid an empty field in my postbit.
Boofo
05-10-2003, 10:14 PM
In newreply.php, find:
// ############################### start post reply ###############################
if ($HTTP_POST_VARS['action']=="postreply") {
// check for subject and message
$message=trim($message);
if ($message=="") {
eval("standarderror(\"".gettemplate("error_nosubject")."\");");
exit;
}
BELOW it add:
if ($postinfo[title]!="") {
$title="Re: ".htmlspecialchars($postinfo[title]);
}
$title = str_replace("Re: Re: ", "Re: ", $title);
Still in newreply.php, find:
$title=censortext($title);
$message=censortext($message);
ABOVE it add:
if ($title=="") {
$title="Re: ".$thread[title];
} else {
$title=$title;
}
$title = str_replace("Re: Re: ", "Re: ", $title);
If you have the multiple quotes hack installed, there is a couple more places you will need it, too. Let me know if you need that also.
Falkware
05-22-2003, 12:28 AM
Thank you..got it working now. Also made it put it in using the quick reply box.
Appreciate the help.
Boofo
05-22-2003, 09:54 AM
Yesterday at 08:28 PM Falkware said this in Post #17 (https://vborg.vbsupport.ru/showthread.php?postid=398279#post398279)
Thank you..got it working now. Also made it put it in using the quick reply box.
Appreciate the help.
How did you do that?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.