Forums / Cotonti / Support / SQL troubles

TwistedGA
#1 2009-03-07 02:27
Hey guys, I'm working on another plugin and I'm having a bit of trouble out of it.
I make my sql_squery using '$sql = sed_sql_query' to define it, and it works almost as it should, but since the php it's hooked into already has a $sql, the plugin running causes problems with the original sql query. (It makes al but one of it's results disappear).

So my first thought was to change mine to $sql2. This causes my results to display twice instead of just once as it should. I tried a ton of different names for it and they all cause the same issue, two of the same result.

Anyone have any ideas on how I can correct this issue? Thanks in advance..

EDIT// This thread can be deleted if nothing comes of it in a few days.
I'm not using the same methods so this is no longer a problem for me, however, if anyone has information on it, I woudl love to hear about it and I'm sure it will benifit someone down the road.
[color=#CC0000]Lazymod[/color] [color=#000000]Studios[/color]

Dit bericht is bewerkt door TwistedGA (2009-03-07 03:46, 15 jaren ago)
Kilandor
#2 2009-03-07 07:04
If your code is showing twice then its a problem somewehre else, it has nothign to do with the name.

NEVER NEVER NEVER use generic $sql names, or $sql2 I always recommend $sql_something, or $plug_something, it doesn't matter it doesn't even have to be $sql
GHengeveld
#3 2009-03-07 07:14
You should use sed_sql_query instead of mysql_query.

@Kilandor: What is the reason not to use $sql? Is it because its more vulnerable to attack (its easy to guess), or because it has the risk of being executed in the wrong place. I quite often use $sql so I'd like to know why I shouldn't.
By the way, using $sql multiple times shouldn't be a problem, as long as the value gets overwritten every time. Very often I have something like this:
$sql = "SELECT * FROM sometable WHERE somecondition='true'";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
echo $row['somevalue'];
}
$sql = "SELECT * FROM anothertable";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
doSomething();
}
Kilandor
#4 2009-03-07 07:18
No reason you dont' want to use somethign generic liek that is to many things use it, especially in the core. As he said using it messed up the orginal query.

There are many cases where using generic queries especially hooking will break thins.

Its just good practice not to do that.
TwistedGA
#5 2009-03-07 09:58
$multiquote = sed_import('multiquote','G','TXT');
	if ($multiquote>0)
	{
                $multi = $multiquote;
		$sql_test = sed_sql_query("SELECT fp_id, fp_text, fp_postername, fp_posterid FROM $db_forum_posts WHERE fp_topicid='$q' AND fp_sectionid='$s' AND fp_id IN ( $multi )");

		while ($row4 = sed_sql_fetcharray($sql_test))
		{
			$newmsg .= "[quote][url=forums.php?m=posts&p=".$row4['fp_id']."#".$row4['fp_id']."]#[/url] [b]".$row4['fp_postername']." :[/b]\n".sed_stripquote($row4['fp_text'])."\n[/quote]\n\n";
		}
	}

So I'm still having the repeat issue. For whatever reason, this code is not just running a single time, instead it runs for each post on the page. If theres a single post, it works how it should, 5 posts on the page, it repeats 5 times.

The only way to make it stop running for each post present on the page, is to name "sql_test" "sql"... Which in turn removes all but the first post on the page(not what I want to happen obviously).

I'm stumped on what to try that I have not already. I'm certain it's something minor, but it's a problem nonetheless. I'm working my arse off to fix it and release this..

EDIT//
Also note that this worked perfectly when it's in the core. These problems of repeating are coming from conversion to plugin. It only works when hooked into the forums.posts.loop, everywhere else the code is ineffective. The code works in the core ONLY if the code is placed right below these lines;
/* === Hook - Part1 : Set === */
$extp = sed_getextplugins('forums.posts.loop');
/* ===== */

Apparently, I'm retarded and don't know how to make it insert it right below that. I thought Hooks=forums.post.loop made it insert it right below that. I guess it's Hook - Part2 that defines where it's inserted?
[color=#CC0000]Lazymod[/color] [color=#000000]Studios[/color]

Dit bericht is bewerkt door TwistedGA (2009-03-07 10:30, 15 jaren ago)
Brock
#6 2009-03-07 10:26
It's definitely because of the forums.post.loop. The reason it's repeating is that it's looping for every post, therefore it's going to show every time. As for your problem with forums.posts.tags and such, I am not sure. I think it could be perhaps you are trying to place the tag in a place that is looped, so it's only looking for a forums.posts.loop tag in that area. Of course, this could be totally wrong, but that's what I am assuming is your problem.
Web Design Database - www.wddb.com
TwistedGA
#7 2009-03-07 10:32
Check out my updated post, sorry about that. I don't think it's being in .loop causing it, but where inside the .loop it's being placed. So long as that code is before all the other functions in the .loop, it works awsome, if you move it below any other functions it repeats.. :(

Kinda confusing lol..

EDIT//

I got it to work in the core, under the Hook forums.posts.main, it removed the looping issue so I figured that woudl be the spot to make my plugin hook into, causes a Internal 500 error for whatever reason.. God I love this coding stuff! LOL
[color=#CC0000]Lazymod[/color] [color=#000000]Studios[/color]

Dit bericht is bewerkt door TwistedGA (2009-03-07 10:57, 15 jaren ago)