News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Best Answer

Started by Avalanche91, December 05, 2013, 09:09:24 AM

Previous topic - Next topic

Avalanche91

Please use the latest version of this modification.

Link to Mod

Mod in action

Description:
Best Answer mod gives you the ability to mark a reply in a topic as Best Answer/Solution. The marked answer will be lit in green, showing the other users what exactly is the solution to the topic.
The permission to mark an answer as such has the person who started the topic, or if for any reason he has forgotten to mark anything, moderators and administrators can do this as well.

License
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Languages:
- English
- English UTF8
- British English
- British English UTF8
- Bulgarian
- Bulgarian UTF8
- Turkish
- Turkish UTF8
- Italian
- Italian UTF8
- Brazilian Portuguese
- Brazilian Portuguese UTF8






littlenicki

Hello, this is an excellent mod! Could you please do a SMF 1.1 verson of it? Thanks so much!
Fomer SMF user. Switched to Invision Power Board and VBulletin

Arantor

It would require a total rewrite for 1.1.x.

You should also know that sometime in 2014 we will be discontinuing official support (including security patches) for 1.1.x; once 2.1 goes stable, 1.1 will be end of life.
Holder of controversial views, all of which my own.


4Kstore

I just installed this on a test forum and when I go into a topic this error appears:

Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\ssrs\Sources\Display.php on line 1247

In that line:

$context['ba_jump_to_msg'] = $smcFunc['db_fetch_row']($result)[0];



¡¡NEW MOD: Sparkles User Names!!!

margarett

I can't see that happening.

That line does exist but produces no error in my test forum.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

I suspect that the line BEFORE that has an issue with a missing bracket
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Adrek

Nice mod :)

I have the same error as 4Kstore :|
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Kindred

Quote from: Kindred on December 05, 2013, 01:19:09 PM
I suspect that the line BEFORE that has an issue with a missing bracket

so please include your code for several lines BEFORE the affected line?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Adrek

it's code that this mod adds in Display.php file...



// Let's see if any Answer is marked as Best solution and if True, select all information needed to display
$result = $smcFunc['db_query']('',
'SELECT `ba`.`id`,`ba`.`id_msg`,`ba`.`id_topic`,`ba`.`id_member`,DATE(`ba`.`time_marked`) AS `day`,TIME(`ba`.`time_marked`) AS `time`,`m`.`member_name`
FROM {db_prefix}best_answer AS `ba`
INNER JOIN {db_prefix}members AS `m`
ON `ba`.`id_member`=`m`.`id_member`
WHERE `id_msg`={int:id_msg}',
array('id_msg' => $message['id_msg'])
);
$context['best_answer'] = $smcFunc['db_fetch_assoc']($result);

// Let's create the "jump to" link if we have a Best Answer
if ($context['topic_first_message'] == $output['id']) {
$result = $smcFunc['db_query']('',
'SELECT `id_msg` FROM {db_prefix}best_answer WHERE `id_topic`={int:id_topic}',
array('id_topic' => $output['id'])
);
// Contains the id of the post that was marked as Best Answer
$context['ba_jump_to_msg'] = $smcFunc['db_fetch_row']($result)[0];
}
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Arantor

I knew I should have reviewed the code of this one.

Try replacing the affected line with:
list($context['ba_jump_to_msg']) = $smcFunc['db_fetch_row']($answer);
Holder of controversial views, all of which my own.


littlenicki

Quote from: Arantor Beeblebrox the First on December 05, 2013, 12:40:59 PM
It would require a total rewrite for 1.1.x.

You should also know that sometime in 2014 we will be discontinuing official support (including security patches) for 1.1.x; once 2.1 goes stable, 1.1 will be end of life.

Yes but many users will coninue using the old vesion. As I will do, too, I would really admire it if there was a 1.1 version of this mod available.
Fomer SMF user. Switched to Invision Power Board and VBulletin

Arantor

QuoteYes but many users will coninue using the old vesion. As I will do, too,

So when SMF stops working because PHP has moved on, and/or there are security holes found in the software, these will NOT be fixed. Only a couple of months ago were we advised of holes found in 1.1.x, for example.
Holder of controversial views, all of which my own.


Avalanche91

I apologize for the inconvenience folks. It's because of the "odd" syntax and I am using in this line:
Code (php) Select
$context['ba_jump_to_msg'] = $smcFunc['db_fetch_row']($result)[0];
Apparently PHP 5.4 (or may be v5.3 I am not sure) gives me the flexibility to use the first returned row from the query directly by using this syntax
  • [/b] at the end. So I assume that you guys are using lower version of PHP. Sorry, I just haven't noticed that. I will work out a quick fix for this problem.

Adrek

Arantor, error is gone, but now in logs  I have two another errors:

/index.php?/topic,16431.msg101063.html
2: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
File: /Sources/Display.php
Line: 1259


and Undefined index:

/index.php?/topic,16431.msg101063.html
8: Undefined variable: answer
File: /Sources/Display.php
Line: 1259


Line 1259:
list($context['ba_jump_to_msg']) = $smcFunc['db_fetch_row']($answer);
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Arantor

You really should not be doing that. The semantics of doing so are questionable when you're dealing with variable functions.

list($context['ba_jump_to_msg']) = $smcFunc['db_fetch_row']($result);

is what should have been used - sorry phantomm. Was doing it in a hurry while cooking my dinner.


Also, also please note that links should never be just referenced with ?action or ?topic, they should always be using $scripturl, partly due to subdomain specific conflicts and partly to ensure users who use Pretty URLs or some of the colourising mods won't find it broken.
Holder of controversial views, all of which my own.


Avalanche91

Quote from: phantomm on December 05, 2013, 02:50:38 PM
Arantor, error is gone, but now in logs  I have two another errors:

/index.php?/topic,16431.msg101063.html
2: mysql_fetch_row(): supplied argument is not a valid MySQL result resource
File: /Sources/Display.php
Line: 1259


and Undefined index:

/index.php?/topic,16431.msg101063.html
8: Undefined variable: answer
File: /Sources/Display.php
Line: 1259


Line 1259:
list($context['ba_jump_to_msg']) = $smcFunc['db_fetch_row']($answer);

Could you please try like this:
Code (php) Select
// Contains the id of the post that was marked as Best
$data = $smcFunc['db_fetch_row']($result);
$context['ba_jump_to_msg'] = $data['0'];

Kindred

why not use the code that Arantor suggested?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Adrek

Arantor - now it works fine :)

Avalanche91, your fix also works just fine ;) (PHP 5.2.17)
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

Arantor

Do please note that your second line there only works on a technicality because PHP considers numbers and strings-that-contain-numbers to be the same thing in the hash table it uses for arrays. $data[0] is more proper though works the same way. Using the list construct is the proper way to do it in this situation.
Holder of controversial views, all of which my own.


Avalanche91

Quote from: phantomm on December 05, 2013, 02:56:41 PM
Arantor - now it works fine :)

Avalanche91, your fix also works just fine ;) (PHP 5.2.17)
Thank you very much phantomm. PHP added this quite some time ago along with the new syntax for arrays
Code (php) Select
$myArray = ['value', 'value2'];

Quote from: Arantor Beeblebrox the First on December 05, 2013, 02:57:58 PM
Do please note that your second line there only works on a technicality because PHP considers numbers and strings-that-contain-numbers to be the same thing in the hash table it uses for arrays. $data[0] is more proper though works the same way. Using the list construct is the proper way to do it in this situation.

Oops, you are absolutely correct!

I am going to quickly upload a new version.

Advertisement: