PDA

View Full Version : How to build a table from profile fields data?


valdet
11-17-2008, 10:40 AM
I am trying to build a custom table from few custom profile fields.

Something like the following sketch:

http://img220.imageshack.us/img220/5707/fieldslg2.jpg

Few fields would need to be sorted on ASC or DESC order based on user input.

Does anyone has an idea or hints what is the best way to make something like this?
Maybe an example.


Thanks for your time.

Best regards,
Val.

Lynne
11-17-2008, 02:36 PM
It's just a table on another page? You can start with one of these - How to create your own vBulletin-powered page! (uses vB templates) (https://vborg.vbsupport.ru/showthread.php?t=62164) or [How-To] vBulletin API Basics: Creating Custom Pages & Misc. (https://vborg.vbsupport.ru/showthread.php?t=98009) The fields are just in the database, so a simple query should get them, then just spit them out. Start with getting them outputted, then add in the sort (which would just be a simple switch with the result added to the end of the query as a "ORDER BY..." statement).

valdet
11-18-2008, 12:56 PM
It's just a table on another page? You can start with one of these - How to create your own vBulletin-powered page! (uses vB templates) (https://vborg.vbsupport.ru/showthread.php?t=62164) or [How-To] vBulletin API Basics: Creating Custom Pages & Misc. (https://vborg.vbsupport.ru/showthread.php?t=98009) The fields are just in the database, so a simple query should get them, then just spit them out. Start with getting them outputted, then add in the sort (which would just be a simple switch with the result added to the end of the query as a "ORDER BY..." statement).

Thanks Lynne,

Actually I am trying to display that table on portal homepage (through vBAdvanced). I've posted the question there too.

I am also trying to use the resources found from this post (https://vborg.vbsupport.ru/showpost.php?p=1293628&postcount=3)but didn't have much success so far. :)


The table I am trying to make is a simple one, I only don't know how to populate the columns underneath it.
I would use this code for column titles

<thead>
<tr align="center">
<td class="thead" width="55%">Name</td>
<td class="thead" width="15%">Points</td>
<td class="thead" width="8%">Year</td>
<td class="thead" width="9%">Weight</td>
<td class="thead" width="9%">Height</td>
</tr>
</thead>Thanks for your time.

Lynne
11-18-2008, 01:42 PM
I'm not familiar with vBadvanced at all, so I can't help with any of that. But, the fields you want are in the userfield table. The column 'userid' is the userid, and then the other columns are named 'field1', 'field2', 'field3', etc. So, it should be pretty easy for you to grab that information.

valdet
11-21-2008, 10:32 AM
Well after a lot of hard work, I managed to make a plugin which pulled any profile field I selected.

Currently, it is fetching data from two tables: user and userfield

Here is the result

http://img237.imageshack.us/img237/7840/profilesnl3.jpg

Currently I am sorting these data based only from a single field in my query.
ORDER by userfield.field26 DESC




Here's my question:

What I would like to know, is if there is an easier way to make the titles of these columns clickable (highlighted in red in pic), so when you click the titles (Graduation Year, Height, Weight) the system will sort those columns in accordance with that respective field

The picture will explain it better.

I appreciate your time and looking forward to replies.

Val.

Lynne
11-21-2008, 02:45 PM
What I do on a similar page I wrote, is pass a sort variable. Then I have a switch in my page:
switch ($_REQUEST["sort"])
{
case 'gyasc':
$orderby = "ORDER BY fieldx ASC";
break;
case 'gydesc':
$orderby = "ORDER BY fieldx DESC";
break;
case 'fieldyasc':
$orderby = "ORDER BY fieldy ASC";
break;
case 'fieldydesc':
$orderby = "ORDER BY fieldy DESC";
break;
.........
default:
$orderby = "ORDER BY fieldz DESC";
}


Then I add that variable to the end of my query:

$query = "select blah, blah FROM ".$TABLE_PREFIX."thread as thread WHERE blah, blah' and thread.visible = 1 $orderby $limit";


And then just make your titles clickable and pass the sort variable:
<a href="yourpage.php?sort=gydesc">Graduation Year</a>

Ted S
11-23-2008, 02:33 AM
vBulletin has some great functions and code that you can easily rework with any data that will allow ordering up or down as well as searching, multiple pages, etc... I'd suggest you pick apart memberlist.php and look at the structure used there as well as the various code bits and bring the ones you want into your own script. It may take a little work to bring everything over to a script you wrote from scratch but it will give you more functionality down the road and helps insure your code is optimized to some degree.

valdet
12-02-2008, 10:20 AM
Lynne, Ted, thanks so much for offering me tremendous assistance. I was able to create what I was aiming to.

Now I'll just have to fiddle around with conditionals so various usergroups see different stats.

Here are the screens along with links to DESC ▼ and ASC ▲ ordering


http://img217.imageshack.us/img217/879/37988700ak7.jpg (http://img217.imageshack.us/my.php?image=37988700ak7.jpg)

http://img399.imageshack.us/img399/5329/58039647gj0.jpg (http://img399.imageshack.us/my.php?image=58039647gj0.jpg)

http://img399.imageshack.us/img399/8859/59512713ep9.jpg (http://img399.imageshack.us/my.php?image=59512713ep9.jpg)


Regards.

Lynne
12-02-2008, 02:31 PM
Looks good! :up:

valdet
12-03-2008, 07:18 AM
Thanks Lynne,

I plan to release this when it is fully finished.

Additionally, could you give a hint how could the sorter links ( ▼ and ▲ ) , or templates involved be loaded with Ajax?

Right now when I click on those links all of the page is reloaded.

Thanks,
Val.

Lynne
12-03-2008, 02:18 PM
Ajax is my next area to venture into. I have a little mod on my forum where I plan to try to figure it out. However, I don't think it would be useful in this case. Ajax is used to only 'rebuild' a small part of the page instead of the whole page and thus save on queries. In your case, you need to rebuild the entire table anyway which is most of the queries on the page.

Brandon Sheley
11-03-2009, 05:52 PM
Looks good so far, I'd like to know how to do this as well. :)