PDA

View Full Version : Another PHP question....



deronsizemore
09-07-2006, 11:25 AM
Hey, I'm back with one last php request. I finally got the script to work 100% how it was designed to work. Took some tweaking but finallly got it with some help from you guys! :)

Last thing I'd like to be able to do with this script is after someone clicks a star to rate the article, I would like it to display "Thanks for voting" or something along those lines. Right now, when you click a star, it does nothing. But if you refresh after clicking a star, you'll see the text "this article has been rated X time/s" I'd like to have something just to confirm to people that yes your vote was counted. It's kind of a pet peeve of mine with sites....almost like when you fill out a contact form and get not confirmation and you're left wondering if the person got the message or if there was an error or what? Although, this isn't a HUGE deal.

Anyway, the page again with the rating script on it is http://www.kentuckygolfing.com/courses/3/andover-golf-country-club

and here is the PHP code http://www.deronsizemore.com/rating.txt

If anyone can help, that'd be awesome!

Blue Cat Buxton
09-07-2006, 01:29 PM
Sorry can help this time; cant see where this updates

Chris
09-07-2006, 01:52 PM
That certainly is some complicated mess of code... not your own huh?

deronsizemore
09-07-2006, 02:21 PM
Sorry can help this time; cant see where this updates

I'm not sure what you mean by can't see where it updates? Is there some way I can help you help me? ;)



That certainly is some complicated mess of code... not your own huh?

No, not my code. If I every post any code not html/css then you can certainly bet it's not mine. :D I gave up on trying to learn php and all that a while back. To much work when all I really wanted to do was start publishing sites and there is almost always a solution already made for every situation you run into.

Masetek
09-07-2006, 06:38 PM
I would like to help, but that code is a mess and it would take a fair while to figure out whats going on with it

Chris
09-07-2006, 06:43 PM
I believe by "updates" he means where in the code the database is actually updated, because after that you could simply add "echo "Thank you...blahblah";"

Have you considered javascript? An alertbox that comes up when submitting the form? Not exactly the same but close.

deronsizemore
09-07-2006, 06:44 PM
No problem guys. I definitely understand. Like I said, I don't know PHP so I wouldn't know good code if it hit me in the face. I was just under the impression this was a well put together plugin...looks like I and others at the txp forums are mistaken. lol.

deronsizemore
09-07-2006, 06:48 PM
I believe by "updates" he means where in the code the database is actually updated, because after that you could simply add "echo "Thank you...blahblah";"

Have you considered javascript? An alertbox that comes up when submitting the form? Not exactly the same but close.


Oh, I see. I have no idea where it updates. I'd ask at the textpattern forums, but I get no response there either (maybe because everyone realized the code was a mess?) I was just kinda posting here as a last resort. The plugin works like it should, just wanted to add this last thing in there, but if I can't, not a big deal.

No, I hadn't considered javascript. Would I have to make a form to make that work? Right now there isn't a form that's submitted is there?

Emancipator
09-07-2006, 08:14 PM
that is way to much code for such a simple need. I would help bro but i just dont wanna decode 400 lines of code that could have been done in 10.

deronsizemore
09-08-2006, 04:23 AM
that is way to much code for such a simple need. I would help bro but i just dont wanna decode 400 lines of code that could have been done in 10.


No problem. I guess the guy that designed the plugin just didn't know what he was doing. :) I'll leave it how it is.

Emancipator
09-08-2006, 08:12 AM
well he had to integrate it into a blog system so i am sure he knew what he was doing just had to jump through loops. For mine i use a ajax, and php and its about 20 lines of code. BUT mine is not integrated into somebody elses blog just my own shoddy code :)

deronsizemore
09-08-2006, 09:22 AM
well he had to integrate it into a blog system so i am sure he knew what he was doing just had to jump through loops. For mine i use a ajax, and php and its about 20 lines of code. BUT mine is not integrated into somebody elses blog just my own shoddy code :)

yeah, true. I guess a lot of that PHP code is probably code so that it integrates with Textpattern (adding tabs in the admin page, etc). I think the author said this is suppose to use ajax or ahah (I don't know what ahah is?). Wouldn't know where I could get a better solution that I could maybe customize myself do ya? Or even one that would be easier than this one to customize?

Emancipator
09-08-2006, 07:00 PM
sorry man i write all my own stuff. I found using prebuilt stuff was just not worth the headaches.

KelliShaver
09-10-2006, 01:27 AM
In: http://www.kentuckygolfing.com/ratingjs

Change this:


function tcm_rate(id, rating, element) {
var xhReq = createXMLHttpRequest();
restURL = "http://www.kentuckygolfing.com/rate/"+id+"/"+rating;
//alert(restURL);
xhReq.open("GET", restURL, true);
xhReq.onreadystatechange = function() {
if (xhReq.readyState != 4) { return; }
//rating_input = $('tcm_rating_input');
outerdiv = element.parentNode.parentNode.parentNode;
var serverResponse = xhReq.responseText;
outerdiv.innerHTML = serverResponse;
};
xhReq.send(null);
return false;
}


To this:


function tcm_rate(id, rating, element) {
var xhReq = createXMLHttpRequest();
restURL = "http://www.kentuckygolfing.com/rate/"+id+"/"+rating;
//alert(restURL);
xhReq.open("GET", restURL, true);
xhReq.onreadystatechange = function() {
if (xhReq.readyState != 4) { return; }
//rating_input = $('tcm_rating_input');
outerdiv = element.parentNode.parentNode.parentNode;
var serverResponse = xhReq.responseText;
outerdiv.innerHTML = serverResponse + "Thanks for voting!";
};
xhReq.send(null);
return false;
}

deronsizemore
09-10-2006, 01:26 PM
Kelli, thank you! You're awesome! The only thing I'd like to change if it wouldn't be to much to ask and not some huge undertaking is that once you click a star it tells you "Thanks for voting" which is right...then if you refresh, and then click another star it tells you "You've already rated this course! Thanks for voting!" Is there an easy way to make it so that "Thanks for voting" doesn't show up the second time if the visitor tries to vote again after they've already voted once?

PS: Since you've always been a big help to me, and helping me yet again with this site, if you want it, you're welcome to advertise your services on the site once it launches (no charge of course).

KelliShaver
09-10-2006, 05:53 PM
Thank you. :) I may well take you up on that since you're local.

In answer to your question, I *think* you can do that by putting the javascript back like it was and then changing lines 289 and 294 in your PHP from this:


echo tcm_rating_form(Array('internal' => true, 'id' => $aid));

To this:


echo tcm_rating_form(Array('internal' => true, 'id' => $aid, 'error' => "Thanks for voting!"));

I could be way off base, but give that a try and let me know how it goes.

deronsizemore
09-11-2006, 06:37 AM
Kelli! That's awesome. Worked great, I can't tell you enough how much I appreciate it (I mean that's like 1000 lines of code!) :D

Like I said, about the advertising, it's yours if you want it. I figured it might be of some interest since I am local.

KelliShaver
09-11-2006, 01:32 PM
Glad it worked. :)

Yah, I'll send you a PM about it once I get things sorted out here. Hectic day, I have a project I need to finish up, a fillable 5 page PDF file to create and two proposals to send out still.... but i'll get to you!

For some reason, I also have a splitting headache. I wonder why?

deronsizemore
09-11-2006, 03:35 PM
Glad it worked. :)

Yah, I'll send you a PM about it once I get things sorted out here. Hectic day, I have a project I need to finish up, a fillable 5 page PDF file to create and two proposals to send out still.... but i'll get to you!

For some reason, I also have a splitting headache. I wonder why?


Hmmmm...I wouldn't have any idea about you headache ;)