Displaying list of pick type pods
Good day everyone! Here is my situation and I can't find a solve for it.
My pods config is:
pod: item [ name (txt), desc (txt), type (pick item_type), whose (pick wp_user) ]
pod: type [ name (txt) ]
I use item_type for sorting my item pod. I just put item_type into OPTION element of SELECT. Then I showing all list of item_type pod.
<?php
$item_type = new Pod('item_type');
$item_type->findRecords($orderby = 't.name ASC', $rows_per_page=-1, $where = null, $sql = null);
$total_types = $item_type->getTotalRows();
if( $total_types>0 ) :
while ( $item_type->fetchRecord() ) :
$item_type_name = $item_type->get_field('name');
$item_type_ID = $item_type->get_field('id');
if ($item_type_ID == $_GET['item_type']) echo "<option value='$item_type_ID' selected>$item_type_name</option>";
else echo "<option value='$item_type_ID'>$item_type_name</option>";
endwhile;
endif;
?>
Then I usually make output of my item pod of current user.
So my problem is that I can't understand how to show in OPTION only item_type that has items added by current user. In other words I don't want to show item_type pods which has no items added by current user. (There is no problem to get Id of user).
Sorry for bad english :)
6 Answers
Try this:
<?php
$item_type = new Pod('item_type');
$item = new Pod('item');
global $user;
get_currentuserinfo();
$item_type->findRecords($orderby = 't.name ASC', $rows_per_page=-1, $where = null, $sql = null);
$total_types = $item_type->getTotalRows();
if( $total_types>0 ) :
while ( $item_type->fetchRecord() ) :
$item_type_name = $item_type->get_field('name');
$item_type_ID = $item_type->get_field('id');
$item->find_records('t.id ASC', -1, "type.id = $item_type_ID AND whose.id = $user.id");
if (0 < $item->getTotalRows() ) {
if ($item_type_ID == $_GET['item_type']) echo "<option value='$item_type_ID' selected>$item_type_name</option>";
else echo "<option value='$item_type_ID'>$item_type_name</option>";
}
endwhile;
endif;
Try below:
<?php
global $user_ID;
get_currentuserinfo();
$params = array('orderby' => 't.name', 'limit' => -1, 'where' => 'user.ID = ' . (int) $user_ID);
$item_type = new Pod('item_type');
$item_type->findRecords($params);
and continue on with the remainder of the code you had.
Follow examples and see more about how findRecords works here:
Hello.
Thanks a lot, but I know how to catch user ID. I want to show item_type that has items.
Let's see live sample http://www.epw.su/singlelist/?u=39
There are 3 SELECT boxes with characteristics of added items. All items of this user has item_type = "Продам (Want to sell)" and in first SELECT we're showin all item_types of items that can be.
But I want to show only item_types that has items i.e. we must see in firts SELECT "Продам" only
I hope you will understand my idea. Sorry for bad english =)
I'm having a hard time understanding your english unfortunately, anyone else understand what he's needing? I thought I covered it with the 'where' parameter in findRecords so it only shows items by that user.
I will try to draw my idea ;)

edited Jan 25 at 2:16
Solved!
Thx to chris.pilko! I got your idea and brough it into life in my code=)


