Posts: 2,895
Threads: 59
Joined: Jun 2010
Hi,
Try this:
PHP Code:
<?php
$cmtx_identifier = '1'; // Change this for each of your pages.
define('IN_COMMENTICS', 'true');
require_once "comments/includes/db/connect.php"; // You may need to adjust this path.
$cmtx_identifier = mysql_real_escape_string($cmtx_identifier);
$page_query = mysql_query("SELECT `id` FROM `" . $cmtx_mysql_table_prefix . "pages` WHERE `identifier` = '" . $cmtx_identifier . "'");
$page = mysql_fetch_assoc($page_query);
$id = $page["id"];
$result = mysql_query("SELECT AVG(rating) FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE `is_approved` = '1' AND `rating` != '0' AND `page_id` = '$id'");
$average = mysql_fetch_assoc($result);
$average = round($average["AVG(rating)"] / 0.5) * 0.5;
echo $average;
?>
Have
you completed
the interview?
Posts: 13
Threads: 3
Joined: May 2011
Thank you for answering.
I added the code and uploaded.
It is showing -Access Denied.-
May have to Change some permissios per FTP? Wich ones?
May be importand to know I just upgradet to the Version 2.5.
Posts: 13
Threads: 3
Joined: May 2011
permissions on connect.php is 644.
Is that OK?
Posts: 13
Threads: 3
Joined: May 2011
I did the following.
I changed this part of the Code:
$cmtx_identifier = '1'; // Change this for each of your pages.
define('IN_COMMENTICS', 'true');
to:
$cmtx_identifier = '1'; // Change this for each of your pages.
$cmtx_path = 'comments/';
define('IN_COMMENTICS', 'true');
And Jet the "access denied" is gone.
But it does Show only a "0" . No Stars. It should Show 3 Stars for $cmtx_identifier = '1' .
I would be so happy if you coud help me again Steven .
Posts: 2,895
Threads: 59
Joined: Jun 2010
Hi,
If you're using v2.5 then you need to change the MySQL functions to MySQLi.
I can reply again tomorrow with the code but if you want to do it yourself in the meantime then download the 'Recent Comments' add-on from the add-ons page (it uses MySQLi) and the code there should give you an idea of what you need to do.
Have
you completed
the interview?
Posts: 13
Threads: 3
Joined: May 2011
OK thanks.
My PHP knowledge is not very good, but I will download the add-on and install it.
Then I will try to look at the code and try to do it myself.
I will post tomorow, what I have done.
Posts: 13
Threads: 3
Joined: May 2011
Hello,
I have integrated the "recent Comments" code into my Website. And I deleted most of the code so I have only this:
PHP Code:
<?php
$cmtx_path = 'comments/';
require_once $cmtx_path . 'includes/db/connect.php';
// Start of 'Best Rated' **************************************************************************************************
echo "<h3>Am besten bewertete Depots</h3>";
$comments = mysqli_query($cmtx_link, "SELECT `page_id`, AVG(`rating`) AS `average` FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE `is_approved` = '1' AND `rating` != '0' GROUP BY `page_id` ORDER BY `average` DESC LIMIT 5");
while ($comment = mysqli_fetch_assoc($comments)) {
$average = round($comment["average"] / 0.5) * 0.5;
$page_query = mysqli_query($cmtx_link, "SELECT * FROM `" . $cmtx_mysql_table_prefix . "pages` WHERE `id` = '" . $comment["page_id"] . "'");
$page = mysqli_fetch_assoc($page_query);
echo "<a href='" . $page["url"] . "'>" . $page["reference"] . "</a> (" . $average . "/5)";
echo "<br/>";
}
// End of 'Best Rated' ****************************************************************************************************
?>
There are some similaryties with this:
PHP Code:
<?php
$cmtx_identifier = '1'; // Change this for each of your pages.
define('IN_COMMENTICS', 'true');
require_once "comments/includes/db/connect.php"; // You may need to adjust this path.
$cmtx_identifier = mysql_real_escape_string($cmtx_identifier);
$page_query = mysql_query("SELECT `id` FROM `" . $cmtx_mysql_table_prefix . "pages` WHERE `identifier` = '" . $cmtx_identifier . "'");
$page = mysql_fetch_assoc($page_query);
$id = $page["id"];
$result = mysql_query("SELECT AVG(rating) FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE `is_approved` = '1' AND `rating` != '0' AND `page_id` = '$id'");
$average = mysql_fetch_assoc($result);
$average = round($average["AVG(rating)"] / 0.5) * 0.5;
echo $average;
?>
And, I think there needs to be implemented in a code that the $cmtx_identifier can be taken from MSQLi but i am not able to do this with my php knowledge.
Posts: 2,895
Threads: 59
Joined: Jun 2010
Hi,
The following code is working for me on v2.5.
For the $cmtx_identifier variable, make sure to enter the same value as in your integration code. Don't enter the value that is in the URL when editing the page in Manage -> Pages in the admin panel.
PHP Code:
<?php
$cmtx_identifier = '1'; // Change this for each of your pages.
$cmtx_path = 'upload/'; // You may need to change this.
require_once $cmtx_path . 'includes/db/connect.php';
$cmtx_identifier = mysqli_real_escape_string($cmtx_link, $cmtx_identifier);
$page_query = mysqli_query($cmtx_link, "SELECT `id` FROM `" . $cmtx_mysql_table_prefix . "pages` WHERE `identifier` = '" . $cmtx_identifier . "'");
$page = mysqli_fetch_assoc($page_query);
$id = $page['id'];
$result = mysqli_query($cmtx_link, "SELECT AVG(`rating`)
FROM (
SELECT `rating` FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE `is_approved` = '1' AND `rating` != '0' AND `page_id` = '$id'
UNION ALL
SELECT `rating` FROM `" . $cmtx_mysql_table_prefix . "ratings` WHERE `page_id` = '$id'
)
AS `average`
");
$average = mysqli_fetch_assoc($result);
$average = $average["AVG(`rating`)"];
$average = round($average, 0);
echo $average;
?>
Have
you completed
the interview?
Posts: 13
Threads: 3
Joined: May 2011
Thank you so much Steven.
That works very good.
It is showing me the avarage as a number.
I have coded something that Shows the amount of stars.
I did the following with php if and else:
PHP Code:
<?php
if ($average == 0.5) {
echo '<img src="comments/images/stars/star_half.png">';
} elseif ($average == 1) {
echo '<img src="comments/images/stars/star_full.png">';
} elseif ($average == 1) {
echo '<img src="comments/images/stars/star_full.png">';
} elseif ($average == 1.5) {
echo '<img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_half.png">';
} elseif ($average == 2) {
echo '<img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png">';
} elseif ($average == 2.5) {
echo '<img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_half.png">';
} elseif ($average == 3) {
echo '<img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png">';
} elseif ($average == 3.5) {
echo '<img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_half.png">';
} elseif ($average == 4) {
echo '<img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png">';
} elseif ($average == 4.5) {
echo '<img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_half.png">';
} else {
echo '<img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png"><img src="comments/images/stars/star_full.png">';
}