PDA

View Full Version : Ajax help



afe
12-22-2007, 05:37 PM
Hello can someone run me through installing this http://www.masugadesign.com/the-lab/scripts/unobtrusive-ajax-star-rating-bar please?






Thanks!

BLiZZaRD
12-22-2007, 05:47 PM
After you download the file, unzip it. Inside are two folders, if you are using a MAC, open that folder, if you are not, open the other folder. Inside is a text file named README. read it and it has install instructions inside:



INSTALLATION:

=============================================================================
1. Make your table for the ratings in your db (you should be able to copy
and paste the following SQL)
=============================================================================
CREATE TABLE `ratings` (
`id` varchar(11) NOT NULL,
`total_votes` int(11) NOT NULL default 0,
`total_value` int(11) NOT NULL default 0,
`used_ips` longtext,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=3;


=============================================================================
2. Enter your specific info into _config-rating.php
=============================================================================
$dbhost = 'localhost';
$dbuser = '###';
$dbpass = '###';
$dbname = '###';
$tableName = 'ratings';
$rating_unitwidth = 30;


=============================================================================
3. Enter this line at the top of any page where you want
to have rating bars.
=============================================================================
<?php require('_drawrating.php'); ?>


=============================================================================
4. Point to the right Javascript and CSS files (you need
behavior.js, rating.js, and rating.css)
=============================================================================
<script type="text/javascript" language="javascript" src="js/behavior.js"></script>
<script type="text/javascript" language="javascript" src="js/rating.js"></script>
<link rel="stylesheet" type="text/css" href="css/rating.css" />

Remember to make sure to fix paths for the images as well. I kept behavior.js separate
from rating.js, because you can use it for other things!


=============================================================================
5. Drop the function wherever you want a rating bar to appear
=============================================================================
NOTE: As of version 1.2.1, use the echo statement! Also, if you use the static
parameter, you should always specify the 2nd parameter (number of units), even if
it is blank (which will default to 10 units)

<?php echo rating_bar('8'); ?> - 10 stars (default), ID of 8
<?php echo rating_bar('8xxa','5'); ?> - 5 stars, ID of 8xxa
<?php echo rating_bar('9a','5','static'); ?> - 5 stars, ID of 9a, static (non votable)
<?php echo rating_bar('9b',''); ?> - 10 stars, ID of 9b
<?php echo rating_bar('9c','8','static'); ?> - 8 stars, ID of 9c, static (non votable)


If you want to change how the rating bar is rendered, you will need to edit
the _drawrating.php file. Also, you might need to edit the bottom of the rpc.php
file at about line 52, where the $newback variable is.


Just follow along until complete. :)

afe
12-22-2007, 06:01 PM
I don't understand this, "1. Make your table for the ratings in your db (you should be able to copy
and paste the following SQL)"?

BLiZZaRD
12-22-2007, 06:18 PM
You are creating an SQL database.

Log into phpMyAdmin, open your database you created (or have) that will store this rating system. Click the "SQL" tab and there you will see a large input text box. copy and paste that code into the text box and click go.

It will do the rest.

afe
12-22-2007, 06:25 PM
Thanks!

afe
12-22-2007, 06:35 PM
For making the database do I select all priviliges for the user?





Please and thank you!

BLiZZaRD
12-22-2007, 07:13 PM
Only if you want that username to have access to your database :) it is a general usage that at least one user in each database has complete control, this way you can use scripts to make changes without having to log in to phpMyAdmin each time you want to run a back up or make a small change.

afe
12-22-2007, 07:35 PM
Well, I selected all privilages and I followed all the instructions. Then this is the page I put the rater on. http://www.athletes4excellence.com/liquidlayout1.php . However, I get this message "Parse error: syntax error, unexpected T_STRING in /home/athletes/public_html/rating/_config-rating.php on line 17"

BLiZZaRD
12-22-2007, 07:37 PM
Well, this is where part 2 of the instructions comes in. You need to replace all the ### with your database name and user name and password, etc.

afe
12-22-2007, 07:41 PM
I did that, however, I did not fill out the following.

" $rating_path_db = ''; // the path to your db.php file (not used yet!)
$rating_path_rpc = ''; // the path to your rpc.php file (not used yet!)

$rating_unitwidth = 30; // the width (in pixels) of each rating unit (star, etc.)
// if you changed your graphic to be 50 pixels wide, you should change the value above"

afe
12-22-2007, 07:46 PM
I found what it was. I had '' ##### instead of '#####'.

I get this message now,
"Error: Table 'athletes_rating.rating' doesn't exist"

http://www.athletes4excellence.com/liquidlayout1.php

afe
12-22-2007, 07:48 PM
Wait sorry, never mind, I figured it out.

afe
12-22-2007, 07:50 PM
Wait sorry, never mind, I figured it out and it is amazing, however, I casted a vote and it is taking so long to load, and it is still loading? Can you tested please?

BLiZZaRD you are incredibly amazing!

BLiZZaRD
12-22-2007, 07:51 PM
Can I test it? Sure if you give me a link to the page it is on :)


Sorry, I see the link now...

It doesn't appear to be connecting to the database....



Double check your URIs in the .js files call in the header of the page:



rating/js/behavior.js


try adding a / in front of it like so:



/rating/js/behavior.js


or using the complete URL http://......rating/js/behavior.js

afe
12-22-2007, 08:07 PM
Well, when I add a / infront of rating/... I get this message on the page.

"
Warning: main() [function.main]: open_basedir restriction in effect. File(/rating/_drawrating.php) is not within the allowed path(s): (/home/athletes:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/athletes/public_html/liquidlayout1.php on line 1

Warning: main(/rating/_drawrating.php) [function.main]: failed to open stream: Operation not permitted in /home/athletes/public_html/liquidlayout1.php on line 1

Warning: main() [function.main]: open_basedir restriction in effect. File(/rating/_drawrating.php) is not within the allowed path(s): (/home/athletes:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/athletes/public_html/liquidlayout1.php on line 1

Warning: main(/rating/_drawrating.php) [function.main]: failed to open stream: Operation not permitted in /home/athletes/public_html/liquidlayout1.php on line 1

Fatal error: main() [function.require]: Failed opening required '/rating/_drawrating.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/athletes/public_html/liquidlayout1.php on line 1"

and when I add the complete URL, I get
"Fatal error: Call to undefined function: rating_bar() in /home/athletes/public_html/liquidlayout1.php on line 269
"

BLiZZaRD
12-22-2007, 08:16 PM
Okay, then that isn't it... LOL

I had a look at your rating.css though... the path to the star images is set ../images/starrating.jpg or whatever...

make those (I think there are 4 spots) absolute URLs.

The index example works fine, so there is a path issue somewhere... it may be there.

afe
12-22-2007, 08:36 PM
Ok, now when I cast a vote, it only shows a star. Try it yourself.

afe
12-22-2007, 10:06 PM
I added all of the types, and I reinstalled the script. And I still get that problem. It's still loading and nothing is happening when I cast a vote.

BLiZZaRD
12-23-2007, 02:47 PM
It's okay, it appears to work fine on your server.

What about the CSS in the html page itself:



/**************************
STAR RATER
**************************/
.star-rating li.current-rating{
background: url(star_rating.gif) left bottom;
position: absolute;
height: 30px;
display: block;
text-indent: -9000px;
z-index: 1;
}


I can't find "star_rating.gif" on your server anywhere... not that this prevents anything from working, but without knowing exactly what you are doing, it is hard to disassemble.

I will keep looking.

afe
12-23-2007, 03:45 PM
That has nothing to do with that star rater, it is a previous one that I used!





Thanks

afe
12-23-2007, 04:24 PM
I also changed the page to... http://www.athletes4excellence.com/layout.php

BLiZZaRD
12-23-2007, 05:12 PM
Go this from the download site:



Problem Description: When rating an object the click goes through, but hangs at the working.gif (the swirly). I came across this problem when I wanted to use the rating_bar function outside of the rating directory. i.e. I was calling rating_bar from a file that was not in the same directory as the other rating files (db.php, rpc.php, etc.).

Solution:
All paths that make rating function calls need to be updated with the new directory information. Listed below are the corresponding files and relative area where a path needs changing:

1. Modify _drawrating.php near line 79: change <li><a href="db.php? to <li><a href="../pathToRatingDirectory/db.php?
2. Modify rating.js near line 62: change xmlhttp.open('get', 'rpc.php? to xmlhttp.open('get', '../pathToRatingDirectory/rpc.php? rpc.php

Depending on your directory structure you may have to modify the following paths too:

3. Possibly Modify db.php near line 14: change require('_config-rating.php'); to require('../pathToRatingDirectory/_config-rating.php');
4. Possibly Modify rpc.php near line 15: change require('_config-rating.php'); to require('../pathToRatingDirectory/_config-rating.php');
5. Possibly Modify _drawrating.php near line 13: change require('_config-rating.php'); to require('../pathToRatingDirectory/_config-rating.php');

afe
12-23-2007, 06:45 PM
I did what you told me, now I get "Unknown system variable 'NAMES'" on http://www.athletes4excellence.com/layout.php

BLiZZaRD
12-23-2007, 07:23 PM
DId you do all 5 steps or just the first 2?


Perhaps there is a parsing problem on your server. Perhaps a change is in order for a more robust, easily implemented rating.

you can try this one (http://www.komodomedia.com/blog/index.php/2006/01/09/css-star-rating-part-deux/) which explains it well, and has a link to an updated, more compatible one :)

afe
12-23-2007, 08:10 PM
Yes, I followed all the steps

BLiZZaRD
12-23-2007, 08:27 PM
You can either undo steps 3 through 5, or look at the rating system I linked to in the above edit field. :)

afe
12-23-2007, 08:35 PM
Can you try installing the one I have right now please and show me if it works please?

BLiZZaRD
12-23-2007, 08:50 PM
Install it on my site or yours? I can tell you right now the settings are going to be completely different on my site just based onthe set up and the way the calls are made.

Even if it works I would still have to figure out what the differences are that make it not work on yours.

On the other hand, I can try to re-install it on your site and get it working.

either way. If you want me to try it on yours, I will need the following information (PM or email it to me so it isn't posted here for the world to see)

FTP log in information, SQL address and database name and log in info, and where you want it all set up at.

If you don't I understand, but something like this is generally easier on the end site instead of a third party site. We can see it works on the site it came from, there is just something small and screwy messing with the works right now.

afe
12-23-2007, 08:57 PM
I see, was I suppose to chomd any files?

afe
12-23-2007, 09:33 PM
I did that, however, I did not fill out the following.

" $rating_path_db = ''; // the path to your db.php file (not used yet!)
$rating_path_rpc = ''; // the path to your rpc.php file (not used yet!)

$rating_unitwidth = 30; // the width (in pixels) of each rating unit (star, etc.)
// if you changed your graphic to be 50 pixels wide, you should change the value above"

Also as in my previous post I put, I did not fill out these blanks.

afe
12-23-2007, 10:10 PM
If you want to change how the rating bar is rendered, you will need to edit
the _drawrating.php file. Also, you might need to edit the bottom of the rpc.php
file at about line 52, where the $newback variable is.

What does it mean by that?

afe
12-23-2007, 10:13 PM
I FIXED IT!! I just put the files independently in public_html instead of in a folder and it worked. However, why are there some dots on top the stars when you vote?

BLiZZaRD
12-24-2007, 05:11 AM
I FIXED IT!! I just put the files independently in public_html instead of in a folder and it worked. However, why are there some dots on top the stars when you vote?


Congratulations. It was a path issue then, we just didn't make it to the right file (I understood you made the correct changes to the php files) either way, it works, and if you are satisfied then so am I.

The "dots" are not dots. If you will notice the star image is actually all 3 images of the stars and when used it moves the image to adjust it to show (moves the image up or down and left/right to fill in the blank star image). What you are seeing is the bottom of the star image on top of the gold filled star.

There is probably something in the code that tells it how much to move and if you can find that you can adjust it by a pixel or two, but it is hardly noticable, and I would have never seen it if you hadn't said anything. :)

afe
12-24-2007, 09:09 PM
Thanks a Googol! = 10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000!

afe
12-25-2007, 05:58 AM
I cannot seem to find where to fix it.

BLiZZaRD
12-25-2007, 06:28 PM
There are probably one or more spots in each php file uploaded that call to those directories, some are automated (as with the SQL) and others are relative, and still others I assume will be absolute.

If it is working and you are happy I say leave it be. if not, then you need to go through each and every file, looking for the name of the 3 star image, and changing the relative paths to point to the directory.

afe
12-25-2007, 09:53 PM
Ok thanks! Now my problem is that when I add to other pages, it is the same rater that has been rated. How I want to use this rater is use it to rate videos...





Thanks!

BLiZZaRD
12-25-2007, 10:17 PM
My understanding was that each time you ran the php include it gave a new id. there are two IDs that need to be different, one in the div, and one in the star image.

if <div id="47965"> then image ID should be the same with a "_1" after <img id="47965_1"...

I am not all into this star rater, but it should do this automatically when called correctly. This should be done by the SQl, check that all the tables are being filled correctly.

afe
12-26-2007, 05:58 PM
What would that do? and where is that <div id="47965"> located?

BLiZZaRD
12-26-2007, 07:17 PM
Well, with different IDs, then they won't all be linked to the same one, meaning you can put as many as you want up and they will record differently.

The div ID and such is located int eh HTML after you do the php include. So you will need to find the proper code in the php file that is called from the include.

afe
12-31-2007, 02:52 AM
I did not find any includes in the page I have it, http://www.athletes4excellence.com/layout.php ; all I found were requires, echos, the two js files and the css file.

BLiZZaRD
12-31-2007, 08:24 PM
When you added the code to the page it should have been done with a php code like:



<?php
include '_raterpage.php';
?>


You had to put something there to add the code. require is similar to include though, so you may have used that one.

afe
12-31-2007, 08:40 PM
Ohh, I have <?php require('_drawrating.php'); ?>

that must be it right?

afe
12-31-2007, 09:00 PM
<?php echo rating_bar('8xxa','5'); ?> Is that what I need to change? Because I changed the '8xxa' to what ever, and it changed! And also that's located on the page I have the rater!
Thanks!

BLiZZaRD
01-02-2008, 02:30 AM
<?php require('_drawrating.php'); ?> is the one. look in drawrating.php for the ID stuff.

the rating_bar is an image. Perhaps chaning the 8xxa will work, you can test that. Not sure what calls are on it. the 5 I know is the number of stars it shows.

afe
01-02-2008, 02:46 AM
Yeah changing the "8xxa" worked perfectly! Thank you so much for your help. I could not do it without your help. As I have said before, you are amazing! You are what DynamicDrive.com is about.

afe
01-06-2008, 12:47 AM
Hey Blizzard, I have been trying to fix the problem of my stars not being aligned. On this page, http://www.athletes4excellence.com/sortexample.php it is perfectly aligned. But on my layout page, http://www.athletes4excellence.com/layout.php, the stars aren't aligned and I see the bottoms and tops of them. Can you help me please and thank you?

afe
01-06-2008, 02:13 AM
Hey Blizzard, I was also wondering how I remove the "divid" appearing infront of the "Rating: blah blah". Please and thank you!

BLiZZaRD
01-06-2008, 09:10 AM
In the config file listed above (where you changed the 8xxaa whatever) you will see the paragraph that lists the rater. In that find this line:



<p><div class="ratingblock"><div id="unit_long8xxa"> <ul id="unit_ul8xxa" class="unit-rating" style="width:150px;"> <li class="current-rating" style="width:134.1px;">Currently 4.47/5</li><li><a href="db.php?j=1&amp;q=8xxa&amp;t=24.19.226.186&amp;c=5" title="1 out of 5" class="r1-unit rater" rel="nofollow">1</a></li><li><a href="db.php?j=2&amp;q=8xxa&amp;t=24.19.226.186&amp;c=5" title="2 out of 5" class="r2-unit rater" rel="nofollow">2</a></li><li><a href="db.php?j=3&amp;q=8xxa&amp;t=24.19.226.186&amp;c=5" title="3 out of 5" class="r3-unit rater" rel="nofollow">3</a></li><li><a href="db.php?j=4&amp;q=8xxa&amp;t=24.19.226.186&amp;c=5" title="4 out of 5" class="r4-unit rater" rel="nofollow">4</a></li><li><a href="db.php?j=5&amp;q=8xxa&amp;t=24.19.226.186&amp;c=5" title="5 out of 5" class="r5-unit rater" rel="nofollow">5</a></li> </ul> <p>8xxa Rating: <strong> 4.5</strong>/5 (15 votes cast) </p></div></div></p>

and remove the part in red.

As for the first problem, I am not sure. Check your CSS files for those Div names and see if a height attribute is declared. If one is, make it smaller.

afe
01-06-2008, 06:36 PM
<?php
/*
Page: _config-rating.php
Created: Aug 2006
Last Mod: Mar 18 2007
Holds info for connecting to the db, and some other vars
---------------------------------------------------------
ryan masuga, masugadesign.com
ryan@masugadesign.com
Licensed under a Creative Commons Attribution 3.0 License.
http://creativecommons.org/licenses/by/3.0/
See readme.txt for full credit details.
--------------------------------------------------------- */

//Connect to your rating database
$rating_dbhost = 'localhost';
$rating_dbuser = 'BLAH;
$rating_dbpass = 'BLAH';
$rating_dbname = 'BLAH';
$rating_tableName = 'BLAH';
$rating_path_db = ''; // the path to your db.php file (not used yet!)
$rating_path_rpc = ''; // the path to your rpc.php file (not used yet!)

$rating_unitwidth = 30; // the width (in pixels) of each rating unit (star, etc.)
// if you changed your graphic to be 50 pixels wide, you should change the value above

$rating_conn = mysql_connect($rating_dbhost, $rating_dbuser, $rating_dbpass) or die ('Error connecting to mysql');
//mysql_select_db($rating_dbname);

?>



That's what the config file contains and I also tried _drawrating.php and it didn't have what you wrote either.
And on the page that I put the rater on, All I have to put is "<?php echo rating_bar('8xxa','5'); ?>" and change the "8xxa". So I couldn't find what you posted above anywhere.
Thanks.



And for the stars not aligning problem, I could not find that either. It is perfect on this page http://www.athletes4excellence.com/sortexample.php, but on this page it is not http://www.athletes4excellence.com/layout.php

Why is it perfect on that page, and it is messed up on this page http://www.athletes4excellence.com/layout.php?

afe
01-12-2008, 10:53 PM
Still can't get it to get fixed...

afe
01-21-2008, 04:44 AM
Gosh! Still don't know why it's like that!! Please help and thanks Blizzard! :)