Back to this post Mark, did you try the code sample I indicated in a template? Make sure you have error reporting enabled in your environment. Testing is important as well, surely this latest version is not behaving as you’d expect it to, unless you are testing with the Getting Started entry that comes installed with EE.
Ah ok, but still, this does not account for the error it might throw, because if there are no rows in the query result
if ($query->row['entry_id'] != 1)
this will throw an error as there’s not ‘entry_id’ in the row array, whereas
if ($query->num_rows != 1)
will always exist, num_rows as the property of the $query object will exist even if no rows were selected. Do you see the difference? In my example, I’m not accessing any array field of the $query->row property.
Hi Guys,
Thanks for the help on this but I have to admit that now I am really really confused :down:
Back to this post Mark, did you try the code sample I indicated in a template? Make sure you have error reporting enabled in your environment. Testing is important as well, surely this latest version is not behaving as you’d expect it to, unless you are testing with the Getting Started entry that comes installed with EE.
Hi Derek,
I tried that code, I guess that I was supposed to surround it with php tags first though? By error reporting do you mean the :
Admin->System Preferences->Output and Debugging Preferences->Debug Preference
or something else perhaps?
I tried placing the code you showed in a template with PHP enabled with surrounding PHP tags and visited the template but just got a blank page with no source to it. Is that what I should expect to see? If so then I am completely dumb as I don’t quite get what it all means I’m afraid.
As to the version that I have on my system it is working fine with any entry and any weblog so not too sure why you would think it would only work with the Getting Started entry which I always delete upon installing ExpressionEngine anyway. Any more information as to where I am going wrong would be great though although at the moment I am seeing this all working the way I expect it to unless I really am WAY too tired and completely missing the point?
Ah ok, but still, this does not account for the error it might throw, because if there are no rows in the query resultthis will throw an error as there’s not ‘entry_id’ in the row array, whereasif ($query->row['entry_id'] != 1)
will always exist, num_rows as the property of the $query object will exist even if no rows were selected. Do you see the difference? In my example, I’m not accessing any array field of the $query->row property.if ($query->num_rows != 1)
I have to completely throw my hands in the air now and say that I’m afraid I didn’t understand this part, sorry :down:
I have uploaded the ‘test’ version which I have on my system which to me seems to be working fine in the way that I want it to which is that if a person has already posted a comment to the entry then they aren’t allowed to post again and the other way being that if they haven’t posted a comment yet then they are allowed to.
If possible could you explain to me in simpleton terms (as that is what I must be 😉 ) what it is that I am still doing wrong and why it isn’t working as I see it on my system as indeed working.
Thanks for the help on this. I read through all the developer guidelines and I am trying to apply everything there to my code as far as I can but still it looks like I am obviously not quite getting it all :down:
Best wishes,
Mark
Mark, I’m trying to guide you there in way that will lead to a lasting impression of the knowledge gained, instead of just giving you the direct code you need. It will be much to your benefit if you first discover why what you’re doing is wrong before moving on.
See this KB article about blank pages, and enabling PHP errors. And yes, the code will need PHP tags around it, and reference the global $DB object just as you are doing in your plugin. A cut and paste for your template would be:
<?php
global $DB;
$query = $DB->query("SELECT entry_id FROM exp_weblog_titles WHERE entry_id != entry_id LIMIT 1");
$entry_id = $query->row['entry_id'];
?>
Hi Derek,
Thanks for that. I totally see where you are coming from and I definitely don’t want to just be given the answer as I don’t like learning that way anyway so that is all understood.
Thanks for the KB article. I had to put both E_ALL in and also the ini_set(‘display_errors’, 1); in order for an error to show and so now get :
Notice: Undefined index: entry_id in /Applications/MAMP/htdocs/eetest/admin/core/core.functions.php(637) : eval()'d code on line 5
using the query that you supplied above. I must say though that even though I realise that the query could never come back with a result as it doesn’t make sense but this now has me even more confused as what I am doing would always bring back a result wouldn’t it? With the ‘test’ plugin that I posted 2 entries above it does all seem to be working as it should be on my system and not just with the standard Getting Started entry as I always delete that one anyway so this now has me doubly confused as I can see it working so not too sure exactly what it is that I am doing wrong really?
Thanks for taking time out to try and explain all this to me but I think that I must be really slow or something as I still don’t quite get what is wrong with what I have done. Obviously there is something there and I’m sure if I read over all this around 1,000 times then I will get it soon enough!! 😉 😊 😉
Thanks again for the time on this one. Off to see if I can get all of this drummed into my thick-skull!!
Best wishes,
Mark
It would only bring back a result if the value fed to the parameter is a valid URL title for the weblog. Can you always be sure that that will be the case?
$query = $DB->query("SELECT entry_id FROM exp_weblog_titles WHERE url_title = '".$DB->escape_str($url_title)."' AND weblog_id = '".$DB->escape_str($weblog_id)."'");
if ($query->row['entry_id'] != 1)
I know you’re getting your desired effect, but look closely here, Mark. When will $query->row[‘entry_id’] ever be equal to 1?
$weblog_id = (preg_match('/[^0-9]/', $weblog_id = $TMPL->fetch_param('weblog_id'))) ? FALSE : $weblog_id;
Your mind’s in the right place, wishing to validate this, but that validation can occur as part of the query, so long as you escape that string. If a bad weblog ID or non-numeric is given, the query will not be able to return results. Since you aren’t preventing that query from running if the supplied weblog id is invalid, that’s a wasted regular expression. An alternative would be to bail out of the plugin if the supplied parameters aren’t valid, preventing any queries from being executed, and allowing the conditional to evaluate as FALSE, which brings me to my last point.
You are explicitly setting ‘already_spoken’ to TRUE, which is fine, but what value will it have if the code you are using doesn’t allow it to be set as such?
Mark - I’m getting a nasty error when I use this plug-in.
Notice: Undefined index: entry_id in /home/something-lala/public_html/something-lala/plugins/pi.one_voice.php on line 58
Notice: Undefined variable: entry_id in /home/something-lala/public_html/something-lala/plugins/pi.one_voice.php on line 65
Hi Grant,
Sorry about that. I haven’t had a chance to finish this one off as of yet as other jobs unfortunately got in the way of this.
If I get a chance in the near future then I will surely update this thread and let everyone know at the soonest moment.
Sorry about that :down:
Best wishes,
Mark
Hi Grant,
Just out of interest are you trying to use this on a page that has the entry_id tacked on the end of the URL as opposed to a url_title?
This would at the moment cause problems with the way I had written it as I was having a bit of a senior moment when I wrote the plugin in that I had only written it for pages that have a url_title in them. I completely forgot that this :
http://www.example.com/blog/detail/11
could also hold true for an entry.
Let me know how you are using it and I will see if I can come up and get this thing working soon.
Best wishes,
Mark
Hiya,
Well that’s actually two issues!! 😉
I had written the plugin so that you put in the weblog_id yourself. Placing in {weblog_id} won’t work as this plugin is wrapped around the comments form and so at that point the {weblog_id} variable isn’t available.
With the entry_id as opposed to url_title part I am trying to find a way as to how you get at each of those. Do you always have your entry_id / url_title as the last segment?
If so then I could just provide an extra parameter called :
mode=”url_title” or mode=”entry_id”
That way you could specify which you want and then I can just grab the last segment and that should hopefully work.
Best wishes,
Mark
Hey good buddy.
I have it setup a bit different where then comment form is wrapped with the weblog entries tags. So it would pull the weblog id from the entry.
Do you always have your entry_id / url_title as the last segment?
Yeah, pretty much.
If so then I could just provide an extra parameter called : mode=”url_title” or mode=”entry_id” That way you could specify which you want and then I can just grab the last segment and that should hopefully work.
Dude! That would totally rock! :coolsmirk:
Hmm not too sure why you have the weblog tag surrounding the comment form but I suppose you are doing that for some specific reason?
Having said that I just tried it out and it wouldn’t work for me either. I didn’t get any errors but then I have been working on the plugin a bit since then. Actually now I am looking at it some more I’m not really sure why I needed the weblog_id because the entry_id or url_title should be enough for me to get this working - I think 😉
Will take another look at this one either tonight or tomorrow and see what I can come up with.
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.