The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
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:
character name : testcharlie testcharlie but the second user, should have been testjohn and if more was added then ofcourse they should appear. |
#2
|
|||
|
|||
I have a couple of questions - I think I understand what you want to happen.
I'm presuming you're running on vB4. * Whereabouts would this template/php run from? * Are you aware of the vb:foreach function available in templates? * Are you sure your SQL query is working correctly? Do you have any access to something like phpMyAdmin to be able to test your query? An abridged version of the code I wrote to pull all unread posts from subscribed threads is below - followed by the template code which displays the posts in forum sidebar. PHP Code:
HTML Code:
<vb:each from="posts" key="postid" value="post"> <li class="avatarcontent floatcontainer"> <a class="smallavatar"> <vb:if condition="$post['showavatar']"> <img width="30" title="" src="{vb:raw post.avatarurl}" alt=""/> <vb:else /> <img width="30" title="" src="{vb:stylevar imgdir_misc}/unknown.gif" alt=""/> </vb:if> </a> <div class="smallavatartext"> <p><a href="{vb:raw post.url}" class="title">{vb:raw post.title}</a></p> <p>{vb:raw post.message}</p> <div class="meta"> by <a href="{vb:raw post.memberurl}">{vb:var post.username}</a> at <span class="time">{vb:raw post.time}</span> {vb:raw post.date} </div> </div> </li> </vb:each> Have you considered this sort of approach? I'm happy to give you a better look at my code and how I implemented it if you PM me. |
#3
|
|||
|
|||
Whatever you do about this PLEASE try not to put database queries in while/for/foreach loops. Performance of the code will be really awful.
I'm not entirly sure what it is you are trying to do; could you explain your application better? |
#4
|
||||
|
||||
changed my table's instead to work better..
and solved it that way. just some huge query with 35 colums, hehe before i was running 35 querys where each was a row |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|