Respect In Gaming |
| | Who feels like helping with some code? | |
| | |
Author | Message |
---|
Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Who feels like helping with some code? Fri Dec 10, 2010 1:26 pm | |
| Hey everyone, I'm not a scripter/designer. I know html, css, and the very basics of javascript, php, et c. I am by no means a "designer". That being said, I am skinning my site, and I've set up a few interesting things (like rollover buttons, et c). Anywho, to the point: I want to swap a predefined image object in phpBB3 based on count. Shy of replacing the predefined image in the php object with a direct string link, I don't know how to do it. (And I would rather have it call the template object rather than a direct hotlink). So here's the object inside the foreach loop: - Code:
-
'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($poll_option['poll_option_total'] / $poll_option['poll_total'] * 250)); The object ($user->img(poll_center')) is defined in another file (which I'm having a hard time finding) but should be giving a value of: ./themes/MyTheme/imageset/poll_center.png*12*1 with the option to set alt (first comma value) and width (second comma value which multiplies the 1). So what I want to do is call for 0_poll_center.png, 1_poll_center.png, et cetera. How do I do this? Can I explode the object and create a new array, then implode it? | |
| | | azarhal
Posts : 866 Join date : 2010-11-10 Age : 41 Location : Frosty Canada
Ingame Characters Character Name: Gloriana Class: Smuggler Guild: Maybe Serenity
| Subject: Re: Who feels like helping with some code? Fri Dec 10, 2010 2:53 pm | |
| Without seeing all the code kind of hard to understand what is going on here. Never played with phpBB either. $user->img() isn't an object, but it return an object. img is a function, it probably fetch the correct little images to display for the "progress bar" depending on the parameters received. $user is an object though. The function probably have access to the images sources. No idea if it's an array though. 'poll_center' <= This is the name of the image from what you are saying. This mean you can change it to fetch another image as long as: - the image is in the same repertory as the poll_center image - the image path is never hard-coded in the code (which I doubt). you can modify the 'poll_center' to have the image name that you want. You can make an easy try with a static '0_poll_center' to see if my idea is correct. If it work, read about php string concatenation. Create a index value that increase for each loop and add it to the poll_center string to get the right image name. No idea if this helped or not. | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Fri Dec 10, 2010 3:15 pm | |
| Oh, I got that part (index value). Yes, the $user is a global array, defined over several function_*.php pages which get included in every call to a page. There's function.php, function_user.php, function_display.php, et cetera ad nauseum.
The problem is that I want to (outside of the foreach loop, beforehand) retrieve the return from $user->img('poll_center') so that I can insert another option -- like the options for width and alt message.
Those returns are always defined elsewhere. i.e. it doesn't call for the path directly, it would call for {T_THEME_PATH} . {CENTER_POLL_IMAGE} or something. So I need to discover what that is, first, I guess... and then discover how to insert into that like so: {T_THEME_PATH} . $option_num . {CENTER_POLL_IMAGE}
See what I mean?
But since I can't find where $user->img is defined/listed, and how it's imploded, I can't figure out how to do it.
And other than having seen explode/implode commands, I'm not real clear on how to do this.
(edit) So it's not really concatenation I want to do (which would be easy) but instead "insert into after". Which in order to do I think I need to do something like $newval() = explode($user->img['poll_center']) then do a foreach $newval() blah blah blah find out what's in there insert into $newval() blah blah blah MYVAL blah blah implode $newval
then replace $user->img() from the original code for my new thingy $newval. um My head hurts just thinking about it... | |
| | | Selven The Old Bat
Posts : 497 Join date : 2010-11-07 Location : Norway
Ingame Characters Character Name: Selven Class: Jedi Consular Guild: Serenity
| Subject: Re: Who feels like helping with some code? Fri Dec 10, 2010 3:51 pm | |
| Maybe I'm not thinking clear (very possible) but why not download the image you want to replace and edit/change it into what you wanted? Then just upload the new image to the board? Anyway, if I'm not getting the issue at hand, I'm pretty sure they can help you at the PhPBB forums. They've been very helpful to me in the past. I've never messed with codes on that level, more on the display/features in a forum, so I wouldn't dare suggest how to write that code | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Fri Dec 10, 2010 3:58 pm | |
| The thing is that phpbb only supports a single image for polls (er, 3 images making 1 image total) - they have added into the ProSilver style the ability to have multiple colors by *not* using images but instead using border and bg colors in CSS and defining a span for the poll option instead of using the images. I want to use images but have each option display be a different color. So... yeah. I posted on the phpBB forums 3 days ago (and the area51.phpBB forums as well) and have not had a single reply. S'ok. I'll play with it when my webhost fixes the darned name servers... lol. Thanks for trying. I'll keep you posted. | |
| | | Quince
Posts : 176 Join date : 2010-11-17 Age : 65 Location : Durham, NC
Ingame Characters Character Name: Qint B'san Class: Imperial Agent Guild: Crazies of Korriban
| Subject: Re: Who feels like helping with some code? Fri Dec 10, 2010 4:54 pm | |
| Um, I have little background in PHP and this idea may be completely off the wall, but if it only supports one image, why not merge the images into one image and display the part you want using offsets and a fixed frame. Of course if the images aren't the same size, this technique gets kind of tricky. | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Fri Dec 10, 2010 4:58 pm | |
| I think I see what you're saying. Instead of modding the php file, I go into the template and do some fancy CSS to place the image in a container with position 0 0, 0 100%, 0 200%, et cetera, just like the mouseover buttons....? (using a merged image instead of 5 separate ones)
Hm. I think I could do that...
You're a genius. | |
| | | Quince
Posts : 176 Join date : 2010-11-17 Age : 65 Location : Durham, NC
Ingame Characters Character Name: Qint B'san Class: Imperial Agent Guild: Crazies of Korriban
| Subject: Re: Who feels like helping with some code? Fri Dec 10, 2010 5:01 pm | |
| - Velaxi wrote:
- I think I see what you're saying.
Instead of modding the php file, I go into the template and do some fancy CSS to place the image in a container with position 0 0, 0 100%, 0 200%, et cetera, just like the mouseover buttons....?
Hm. I think I could do that...
You're a genius. Heh, nah, I just don't limit myself to inside the box in my solutions. I was a professional software designer/developer for almost 30 years, my bag has lots of tricks in it. I just don't have much need for those skills any more. Glad I could at least put a germ of an idea in your head. | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Sat Dec 11, 2010 5:25 pm | |
| So here's what I did....(and it took me a day to figure out ): First, I made my saber images into 1 merged image, with each blade being 12px, the whole thing is 60px. Same for the end-caps (sabers look stoopet if they're ending square!). Then, I edited my viewbody template like so: HTML template: - Code:
-
<td align="left"> <div align="left" class="pollholder"> <span align="left" class="pollsaber">{POLL_LEFT_CAP_IMG}</span> <span align="left" class="pollmid" style="background-position: <!-- IF poll_option.POLL_OPTION_ID == 1 and poll_option.POLL_OPTION_PCT != 0 -->0 0;<!-- ELSEIF poll_option.POLL_OPTION_ID == 2 and poll_option.POLL_OPTION_PCT != 0 -->0 -12px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 3 and poll_option.POLL_OPTION_PCT != 0 -->0 -24px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 4 and poll_option.POLL_OPTION_PCT != 0 -->0 -36px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 5 and poll_option.POLL_OPTION_PCT != 0 -->0 -48px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 6 and poll_option.POLL_OPTION_PCT != 0 -->0 0;<!-- ELSEIF poll_option.POLL_OPTION_ID == 7 and poll_option.POLL_OPTION_PCT != 0 -->0 -12px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 8 and poll_option.POLL_OPTION_PCT != 0 -->0 -24px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 9 and poll_option.POLL_OPTION_PCT != 0 -->0 -36px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 10 and poll_option.POLL_OPTION_PCT != 0 -->0 -48px;<!-- ELSE -->0 12px;<!-- ENDIF -->"><span class="pollhide">{poll_option.POLL_OPTION_IMG}</span></span> <span align="left" class="pollright" style="background-position: <!-- IF poll_option.POLL_OPTION_ID == 1 and poll_option.POLL_OPTION_PCT != 0 -->0 0;<!-- ELSEIF poll_option.POLL_OPTION_ID == 2 and poll_option.POLL_OPTION_PCT != 0 -->0 -12px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 3 and poll_option.POLL_OPTION_PCT != 0 -->0 -24px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 4 and poll_option.POLL_OPTION_PCT != 0 -->0 -36px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 5 and poll_option.POLL_OPTION_PCT != 0 -->0 -48px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 6 and poll_option.POLL_OPTION_PCT != 0 -->0 0;<!-- ELSEIF poll_option.POLL_OPTION_ID == 7 and poll_option.POLL_OPTION_PCT != 0 -->0 -12px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 8 and poll_option.POLL_OPTION_PCT != 0 -->0 -24px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 9 and poll_option.POLL_OPTION_PCT != 0 -->0 -36px;<!-- ELSEIF poll_option.POLL_OPTION_ID == 10 and poll_option.POLL_OPTION_PCT != 0 -->0 -48px;<!-- ELSE -->0 12px<!-- ENDIF -->;"><span class="pollhide">{POLL_RIGHT_CAP_IMG}</span></span> </div> </td> I tried to concatenate that so I could get away with 5 IF statements instead of 10, but I couldn't get it to take. It kept giving me blank space. And wrote the following CSS into the stylesheet: - Code:
-
.pollholder { height: 12px; width: 100%; margin: auto -1px; padding: 0; display: block; } .pollsaber { width: 51px; height: 12px; display: inline; margin: 0 -1px; padding: 0; overflow: display; } .pollmid { width: {poll_option.POLL_OPTION_IMG_INFO_WIDTH}px; height: 12px; display: inline; overflow: hidden; margin: 0 -2px; padding: 0; background: transparent url('./styles/platinum2/imageset/poll_center.png') repeat-x; } .pollhide { visibility: hidden; } .pollright { width: 5px; height: 12px; display: inline; overflow: hidden; margin: 0 -2px; padding: 0; background: transparent url('./styles/platinum2/imageset/poll_right.png') no-repeat; } And the result: (of course, it stretches dynamically with the browser window size.) Man, what a headache... that's why I'm sharing, inc. I can save someone else. (p.s.: I edited the viewtopic.php file so that the results sort by (1) most votes then (2) ID. Which means that if you haven't voted they're in order {or as you see, if the votes are =} and after voting most votes goes on top. I also changed it so that the width is 85% for most votes and all following % votes are relative to that. So if one option had 2 votes and the others had 1, the ones with 1 would be 50% of that length.. et c.) | |
| | | azarhal
Posts : 866 Join date : 2010-11-10 Age : 41 Location : Frosty Canada
Ingame Characters Character Name: Gloriana Class: Smuggler Guild: Maybe Serenity
| Subject: Re: Who feels like helping with some code? Sat Dec 11, 2010 5:57 pm | |
| For you if/else can you use math or add PHP?
Because ((x % 5)-1) *-12 give you the result for each if/else, with x equal the poll id. (% is a modulo)
IF poll_option.POLL_OPTION_PCT != 0 -->0 [php code ((poll_option.POLL_OPTION_ID % 5)-1) *-12]px; ...ENDIF
and X will give you the 0, -12, -24, ..., -48
No idea if it's possible though... | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Sat Dec 11, 2010 6:14 pm | |
| Well, I could insert that into the php file itself -- an object definition, I mean. like $option_offset = $poll_option['POLL_OPTION_VOTES'] != 0 ? -12* (($poll_option['POLL_OPTION_ID'] % 5)-1) : 12; and then in the global vars array 'POLL_OPTION_OFFSET' -> $option_offset, This what you're getting at? Then I could just put the offset in the CSS background-image... (P.S.: I did get rid of that 1px space between saber and hilt... you'll see it when I post the updated version if Az's php works. Thanks Az! *edit* - Code:
-
foreach ($poll_info as $poll_option) { $option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0; $option_pct_txt = sprintf("%.1d%%", round($option_pct * 100)); $option_offset = ($poll_total . 0) ? $option_offset = -12 * (($poll_option['poll_option_id'] % 5)-1) : 12; $template->assign_block_vars('poll_option', array( 'POLL_OPTION_ID' => $poll_option['poll_option_id'], 'POLL_OPTION_OFFSET' => $option_offset, 'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'], 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'], 'POLL_OPTION_PERCENT' => $option_pct_txt, 'POLL_OPTION_PCT' => round($option_pct * 100), 'POLL_OPTION_IMG' => ($poll_option['poll_option_total'] > 0) ? $user->img('poll_center', $option_pct_txt, round((($poll_option['poll_option_total'] / $high_poll * 100)) * (8/9)) . '%') : $user->img('poll_center', $option_pct_txt, 0), 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false) ); }
$poll_end = $topic_data['poll_length'] + $topic_data['poll_start'];
$template->assign_vars(array( 'POLL_QUESTION' => $topic_data['poll_title'], 'TOTAL_VOTES' => $poll_total, 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'), 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'), 'L_MAX_VOTES' => ($topic_data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $topic_data['poll_max_options']), 'L_POLL_LENGTH' => ($topic_data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
'S_HAS_POLL' => true, 'S_CAN_VOTE' => $s_can_vote, 'S_DISPLAY_RESULTS' => $s_display_results, 'S_IS_MULTI_CHOICE' => ($topic_data['poll_max_options'] > 1) ? true : false, 'S_POLL_ACTION' => $viewtopic_url,
'U_VIEW_RESULTS' => $viewtopic_url . '&view=viewpoll') );
unset($poll_end, $poll_info, $voted_id); }
Yes? Trying it now... | |
| | | azarhal
Posts : 866 Join date : 2010-11-10 Age : 41 Location : Frosty Canada
Ingame Characters Character Name: Gloriana Class: Smuggler Guild: Maybe Serenity
| Subject: Re: Who feels like helping with some code? Sat Dec 11, 2010 6:44 pm | |
| The offset will need to be calculated before the css is loaded. Don't forget that part. | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Sat Dec 11, 2010 7:54 pm | |
| - azarhal wrote:
- The offset will need to be calculated before the css is loaded. Don't forget that part.
Yep, the page load/construction is always the last php in the file. So, it works! Here's how it looks now: Relevant PHP portion: - Code:
-
foreach ($poll_info as $poll_option) { $option_pct = ($poll_total > 0) ? $poll_option['poll_option_total'] / $poll_total : 0; $option_pct_txt = sprintf("%.1d%%", round($option_pct * 100)); $option_offset = ($poll_option['poll_option_total'] > 0) ? $option_offset = -12 * (($poll_option['poll_option_id'] + 19) % 5) : $option_offset = 12; $template->assign_block_vars('poll_option', array( 'POLL_OPTION_ID' => $poll_option['poll_option_id'], 'POLL_OPTION_OFFSET' => $option_offset, 'POLL_OPTION_CAPTION' => $poll_option['poll_option_text'], 'POLL_OPTION_RESULT' => $poll_option['poll_option_total'], 'POLL_OPTION_PERCENT' => $option_pct_txt, 'POLL_OPTION_PCT' => round($option_pct * 100), 'POLL_OPTION_IMG' => ($poll_option['poll_option_total'] > 0) ? $user->img('poll_center', $option_pct_txt, round((($poll_option['poll_option_total'] / $high_poll * 100)) * (8/9)) . '%') : $user->img('poll_center', $option_pct_txt, 0), 'POLL_OPTION_VOTED' => (in_array($poll_option['poll_option_id'], $cur_voted_id)) ? true : false) ); }
$poll_end = $topic_data['poll_length'] + $topic_data['poll_start'];
$template->assign_vars(array( 'POLL_QUESTION' => $topic_data['poll_title'], 'TOTAL_VOTES' => $poll_total, 'POLL_LEFT_CAP_IMG' => $user->img('poll_left'), 'POLL_RIGHT_CAP_IMG'=> $user->img('poll_right'), 'L_MAX_VOTES' => ($topic_data['poll_max_options'] == 1) ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $topic_data['poll_max_options']), 'L_POLL_LENGTH' => ($topic_data['poll_length']) ? sprintf($user->lang[($poll_end > time()) ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($poll_end)) : '',
'S_HAS_POLL' => true, 'S_CAN_VOTE' => $s_can_vote, 'S_DISPLAY_RESULTS' => $s_display_results, 'S_IS_MULTI_CHOICE' => ($topic_data['poll_max_options'] > 1) ? true : false, 'S_POLL_ACTION' => $viewtopic_url,
'U_VIEW_RESULTS' => $viewtopic_url . '&view=viewpoll') );
unset($poll_end, $poll_info, $voted_id); } Template Section: - Code:
-
<div align="left" class="pollholder"> <span align="left" class="pollsaber">{POLL_LEFT_CAP_IMG}</span> <span align="left" class="pollmid" style="background-position: 0 {poll_option.POLL_OPTION_OFFSET}px;"><span class="pollhide">{poll_option.POLL_OPTION_IMG}</span></span> <span align="left" class="pollright" style="background-position: 0 {poll_option.POLL_OPTION_OFFSET}px;"><span class="pollhide">{POLL_RIGHT_CAP_IMG}</span></span> </div> I left the CSS file alone, I don't like putting options in curly braces in CSS, too easy to get confused. And the end result... (showing a different poll so you can see the widths. ) Thanks a million for your help, Azarhal! This is what I wanted to do from the start, keep as much as I could in the php to keep it short & sweet. I'm happy with the end result. | |
| | | azarhal
Posts : 866 Join date : 2010-11-10 Age : 41 Location : Frosty Canada
Ingame Characters Character Name: Gloriana Class: Smuggler Guild: Maybe Serenity
| Subject: Re: Who feels like helping with some code? Sat Dec 11, 2010 9:07 pm | |
| | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Sat Dec 11, 2010 9:46 pm | |
| Thanks, you do good work. | |
| | | azarhal
Posts : 866 Join date : 2010-11-10 Age : 41 Location : Frosty Canada
Ingame Characters Character Name: Gloriana Class: Smuggler Guild: Maybe Serenity
| | | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Sun Dec 12, 2010 12:27 am | |
| ok let me rephrase that... : YOUZ GAIZ DO GOOD WERK!!!! | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Sun Dec 12, 2010 8:56 pm | |
| Um... small question?
Is it ok to put an if-else case inside an sql result? I.E. I set up my db call to sort by votes descending then by ID.
Can I make it sort by (if has_voted -> votes desc then ID !has_voted -> just by ID)
Just a nit-picker, ain't I? lol | |
| | | azarhal
Posts : 866 Join date : 2010-11-10 Age : 41 Location : Frosty Canada
Ingame Characters Character Name: Gloriana Class: Smuggler Guild: Maybe Serenity
| Subject: Re: Who feels like helping with some code? Sun Dec 12, 2010 10:01 pm | |
| I suppose you have a query in a string? If yes you can just modify it before doing executing it.
Something like:
sqlquery= "select * from toto where titi = whatever order by ID" + (has_voted? "desc": "asc");
| |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Sun Dec 12, 2010 10:27 pm | |
| - Code:
-
$sql = 'SELECT o.*, p.bbcode_bitfield, p.bbcode_uid FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p WHERE o.topic_id = $topic_id AND p.post_id = {$topic_data['topic_first_post_id']} AND p.topic_id = o.topic_id ORDER BY o.poll_option_total DESC, o.poll_option_id"; $result = $db->sql_query($sql); That's the fetch... So... ORDER BY (um... this is where I'm unsure. How do I make a conditional on data that was fetched just now and hasn't yet been assigned outside of $sql?) | |
| | | azarhal
Posts : 866 Join date : 2010-11-10 Age : 41 Location : Frosty Canada
Ingame Characters Character Name: Gloriana Class: Smuggler Guild: Maybe Serenity
| Subject: Re: Who feels like helping with some code? Mon Dec 13, 2010 1:27 am | |
| You don't know the value of "has_voted"? It's fetched by the query? | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Mon Dec 13, 2010 1:54 am | |
| Precisely.
In the mod I have installed which has it's own poll display page, there are 3 separate instances of sql queries for fetching the data, so I just put my sort in the very last one, displayed after determination of has/can vote... In phpBB3 proprietary, however, it's fetched only once and the tables are updated only if and after the user changes the data after fetching, which is admittedly easier on the $sql requests.
So, yeah. I would have to re-order the array after it's already been passed over and sorted. Which I don't know how to do. | |
| | | azarhal
Posts : 866 Join date : 2010-11-10 Age : 41 Location : Frosty Canada
Ingame Characters Character Name: Gloriana Class: Smuggler Guild: Maybe Serenity
| Subject: Re: Who feels like helping with some code? Mon Dec 13, 2010 2:32 am | |
| What the database you are using? MySQL? It might be possible to put a conditional in the order by, but it depends if the DB support it or not. - Code:
-
ORDER BY o.poll_option_total DESC, CASE WHEN has_voted THEN o.poll_option_id ELSE (o.poll_option_id *-1)";
Not sure if this work. CASE doesn't allow you to change the ASC|DESC, but if you set the value into negative it react the same way...apparently. Never tried it. And has_voted might need to be changed, I don't know the variable type. Technically if it's an integer you should had the = 1 (for true). | |
| | | Velaxi Just Married
Posts : 151 Join date : 2010-11-15 Age : 54 Location : Mississauga, ON, CA
Ingame Characters Character Name: Velaxi Class: Jedi Consular Guild: Platinum
| Subject: Re: Who feels like helping with some code? Mon Dec 13, 2010 4:54 am | |
| Thanks Az, I'll give it a shot tomorrow and see how it goes. I'll let you know! | |
| | | Quince
Posts : 176 Join date : 2010-11-17 Age : 65 Location : Durham, NC
Ingame Characters Character Name: Qint B'san Class: Imperial Agent Guild: Crazies of Korriban
| Subject: Re: Who feels like helping with some code? Mon Dec 13, 2010 4:42 pm | |
| Ok, I'm confused, is the "has_votes" a field in your table that you're retrieving with the select? If so, do a query first that checks to see if there are any votes and then build the query that you want based on the results of that query. (I'm assuming that has_voted is a number. If it's a string, change the comparison accordingly.) - Code:
-
$sql = 'SELECT count(*) FROM ' . POLL_OPTIONS_TABLE . ' o, ' . POSTS_TABLE . " p WHERE o.topic_id = $topic_id AND p.post_id = {$topic_data['topic_first_post_id']} AND p.topic_id = o.topic_id AND has_voted > 0"; $result = $db->sql_query($sql);
Then in PHP code, create the select statement based on the returned count so that the sort order will be correct. If you're not dealing with a lot of data (say thousands of rows), the time to do two queries will be negligible. | |
| | | Sponsored content
| Subject: Re: Who feels like helping with some code? | |
| |
| | | | Who feels like helping with some code? | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| |
|