View Single Post
  #1  
Old 01-23-2010, 08:30 PM
Vaupell's Avatar
Vaupell Vaupell is offline
 
Join Date: Apr 2008
Location: Esbjerg, Denmark
Posts: 1,036
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default seeking php help, foreach with destinct selection [ sorted ]

got a table similar to this, just much larger
colum = autoinc for table
columa and columb = unknown data
columc is known data i can select with.

But if i just SELECT * FROM my table WHERE columc=knownvalue
the result will be an array i also need to run through a loop to display

im going to print/echo via templates, <tables> and the template_bit
ill be using will be something like
<tr><td>{vb:raw DataG}</td><td>{vb:raw DataX}

colum|columa|columb|columc
-------+--------+--------+-------
idfield| data1| dataG | data3
idfield| data1| dataF | data2
idfield| data1| dataH | data1
idfield| data2| dataG | data3
idfield| data2| dataF | data2
idfield| data2| dataH | data1
-------------------------------------

Now i want to display DataG from both places (or many more) where DataG is present
but only once pr unique columA

so first i get the unique columa's with sql

$getunique = $vbulletin->db->query("SELECT DISTINCT columa FROM ".TABLE_PREFIX."mytable");

and now im stuck,,
so im thinking maybe assign each unique id's with a id and then
run a loop that collects the data for display

forach ($getunique, ??what value??)
{
-- run the templater registers and renders..
}

i hope its clear what im trying to do

--------------- Added [DATE]1264287288[/DATE] at [TIME]1264287288[/TIME] ---------------

adding code snipittet.. hope it helps to make sence what im trying to do

PHP Code:
$getapplicants $vbulletin->db->query_read("SELECT DISTINCT userid FROM "TABLE_PREFIX ."ewapplication");
while(
$row=$vbulletin->db->fetch_array($getapplicants))
{
 
$geta1=$vbphrase[ewow_app_main_name];
 
$getcharname=$vbulletin->db->query("SELECT * FROM ".TABLE_PREFIX."ewapplication WHERE question='".$geta1."'");
 
$loadcharname $db->fetch_array($getcharname);
 
$charactername $loadcharname['ansver'];

  
$templater vB_Template::create('ew_applicant_list_bit');
  
$templater->register('charname'$charactername);
  
$applicantbit .= $templater->render();

result :

character name :
testcharlie
testcharlie

but the second user, should have been testjohn
and if more was added then ofcourse they should appear.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01777 seconds
  • Memory Usage 1,781KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete