need help in recent comment

Started on the old forum in April 2012 · view the original in the archive · old links redirect here

24 replies · 1,144 views · started 14 years ago · 1 min read

5 participants
asifnayem Developer · 119 posts #1

hi i am with another problem. :/ in my blog, i wanted to show the last comment of the blog posts on recent coment section. ex:

1) aaa commented on 1st blog post(2)
2) ddd commented on 2nd blog post(10)
3) ccc commented on 3rd blog post(1)

my codes are this:

<?
echo "<div class='sidebar-entry'>";

$result = mysql_query("SELECT * FROM comment order by id desc LIMIT 0,10");
while ($row = mysql_fetch_array($result)) {
$tot = @mysql_num_rows(mysql_query("SELECT bid FROM comment WHERE bid='$row[1]'"));
$writer = @mysql_fetch_array(mysql_query("SELECT * FROM user WHERE id='$row[3]'"));
$blogname = @mysql_fetch_array(mysql_query("SELECT * FROM blog WHERE id='$row[1]'"));
$blogn = htmlspecialchars_decode($blogname[2]);
$writer = htmlspecialchars_decode($writer[4]);
echo "<img class='arrow' src='images/dot_red.gif' alt='»'/> $writer commented on <a class='side' href='blogc.php?id=$row[1]'>$blogn</a>(".$tot.")<br />";
}

echo "<div class='block'></div>";
echo "</div>";
?>

my codes shows all the comments which are the last 10. but i need the last comments of all the blog posts, not the comments of the same post. my codes shows like this:

1) aaa commented on 1st blog(2)
2) bbb commented on 1st blog(2)
3) ddd commented on 2nd blog(10)
4) ccc commented on 3rd blog(1)
5) nnn commented on 2nd blog(10)

comment from the same should not come more than once. but i can't make it. please help. i actually feeling shy to seeking help from u guys, coz everytime when i fail to do something i get help from u guys specially something_else. please help to make it work

subzero Super moderator Fellow · 3,954 posts #2

ORDER BY(last_entry) LIMIT(0,1)

You will need to last add to count reply

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

asifnayem Developer · 119 posts #3

im sry its not clear to me.

arnage Lead · 811 posts #4

When you use htmlspecialchars_decode() are you sure that you know what it does? 😕

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
asifnayem Developer · 119 posts #5

arnage wrote: When you use htmlspecialchars_decode() are you sure that you know what it does? 😕

actually my blog is on regional language and thats y i have to use htmlspecialchars_decode(). my langs ar like

&#2438;&#2478;&#2495; &#2472;&#2438;&#2478;&#2495; &#2472;

so is there any better option to show this kinds of words to make this normal! and btw, i stil can't solve my problem in recent comment.

arnage Lead · 811 posts #6

No, you don't. In that case feel free to remove that function. Which is your language? And for comment(s), is that what you want in singular or plural?

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
asifnayem Developer · 119 posts #7

arnage wrote: No, you don't. In that case feel free to remove that function. Which is your language? And for comment(s), is that what you want in singular or plural?

plural ofcourse 🙂 comment(S), i can't succeeded to make it. please help bro. and my lang is bengali, if i remove that function the codes are shown on front end. what should do to show it ok?

something else Fellow · 2,296 posts #8

im still a little confused on what you want.... if you want only the last comment to show but having a unique bid then use:

$result = mysql_query("SELECT * FROM comment GROUP BY bid order by id desc LIMIT 0,10");
arnage Lead · 811 posts #9

asifnayem wrote: plural ofcourse 🙂 comment(S), i can't succeeded to make it. please help bro. and my lang is bengali, if i remove that function the codes are shown on front end. what should do to show it ok?

Bengali language is UTF8 also, so first you need to set encoding of the document itself, in Notepad++ that option is "Encoding > Encode in UTF-8 without BOM"

Than in markup, xml:

<?xml version="1.0" encoding="UTF-8"?>

and meta:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

Those #2438;#2478;#2495; ... simply means that htmlentities() is used on writing and html will parse it into letters without using htmlspecialchars_decode() when encoding is properly set.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
something else Fellow · 2,296 posts #10

using htmlspecialchars_decode() can set you up for session stealing for example this could be posted into your comments:

<iframe src="mysite.con/session-stealing-page.php" height="0" width="0" border="0"></iframe>

Added after 6 minutes:

or they could stop the page from being parsed by making loads of html errors eg:

</html>**<table><iframe>**<script></iframe> etc etc
asifnayem Developer · 119 posts #11

Thanks for this, but i blocked the word iframe/script/html/body/ type words. only youtube link will parse as iframe that is default set. but now i got this problem:

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0
something else Fellow · 2,296 posts #12

you have got a error in your script to do with your $_SESSION[] by the sounds of things your trying to set a global variable to it. you can get rid of that error either by fixing your script or by using 1 of the following:

php.ini

session.bug_compat_42 = 1
session.bug_compat_warn = 0

.htaccess

php_flag session.bug_compat_42 1
 php_flag session.bug_compat_warn 0
asifnayem Developer · 119 posts #13
$result = mysql_query("SELECT * FROM comment GROUP BY bid order by id desc LIMIT 0,10"); 

it seems ok for me exept one thing. that is its showing the first comment of every post, but i want last comment of every post.

something else Fellow · 2,296 posts #14

Try:

$result = mysql_query("SELECT a.* FROM comment INNER JOIN (SELECT MAX(id) AS id FROM comment GROUP BY bid) b ON a.id = b.id LIMIT 10");
asifnayem Developer · 119 posts #15

not working. getting this error:

PHP Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ......
something else Fellow · 2,296 posts #16

does this work?

$result = mysql_query("SELECT MAX(id), * FROM comment GROUP BY bid ORDER BY id desc LIMIT 10");
asifnayem Developer · 119 posts #17

something else wrote: does this work?

$result = mysql_query("SELECT MAX(id), * FROM comment GROUP BY bid ORDER BY id desc LIMIT 10");

no its not working. 🙁

just_m3. Developer · 199 posts #18

asifnayem wrote: no its not working. :(

*supplied argument is not a valid MySQL result resource *check if id field exists in your table 😊

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

asifnayem Developer · 119 posts #19

just_m3. wrote: *supplied argument is not a valid MySQL result resource *check if id field exists in your table 😊

CREATE TABLE `comment` (
  `id` int(11) NOT NULL auto_increment,
  `bid` int(11) NOT NULL,
  `blogid` int(11) NOT NULL,
  `wid` int(11) NOT NULL,
  `uid` int(11) NOT NULL,
  `reply` int(11) NOT NULL,
  `comments` text NOT NULL,
  `time` int(11) NOT NULL,
  `subcomment` int(11) NOT NULL,
  `hasubcomment` int(1) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

my comment table

something else Fellow · 2,296 posts #20

try this: .... if it doesnt work let us know the error

$result = mysql_query("SELECT MAX(id) AS id, bid  FROM comment GROUP BY bid ORDER BY id desc LIMIT 10") OR die(mysql_error());

you may need to add a few more row name above ^

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close