Displaying list of pick type pods

0

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 :)

asked Jan 24 at 3:28

Alexander HIMuk

20

add comment
enter at least 15 characters

6 Answers

1

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;

answered Jan 25 at 2:14

chris.pilko

889

Thanks, I will try to. – Alexander HIMuk Jan 25 at 2:17
add comment
enter at least 15 characters
0

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:

http://podscms.org/codex/findrecords/

answered Jan 24 at 7:45

sc0ttkclark

2936

add comment
enter at least 15 characters
0

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 =)

answered Jan 25 at 1:01

Alexander HIMuk

20

add comment
enter at least 15 characters
0

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.

answered Jan 25 at 1:06

sc0ttkclark

2936

add comment
enter at least 15 characters
0

I will try to draw my idea ;) alt text

answered Jan 25 at 1:58

Alexander HIMuk

20

edited Jan 25 at 2:16

add comment
enter at least 15 characters
0

Solved!

Thx to chris.pilko! I got your idea and brough it into life in my code=)

answered Jan 25 at 12:15

Alexander HIMuk

20

add comment
enter at least 15 characters