show label text of select option rather than its value in cmb2

I am trying to display the label text of my CMB2 select not the value on the frontend. Currently my select field displays a list of a specific custom post type called fleet. When I add $gas = get_post_meta( get_the_ID(), ‘gas__assign’, true ); echo $gas; into the front of my website it is displaying the value which in this case is the post ID. Is there away I can display the selected option instead of the value?

Custom Select

 $gas->add_field( array(
        'name'          => 'Assign',
        'desc'          => 'assign a vehicle',
        'id'            => $prefix . 'gas__assign',
        'type'          => 'select',
        'options'       => get_gas_options('fleettype'),
    ));

Select Field Selection of a CPT

function get_gas_options($a) {
$args = array(
    'post_type'         => 'fleet',
    'orderby'           => 'ID',
    'post_status'       => 'publish',
    'order'             => 'ASC',
    'posts_per_page'    => -1 // this will retrive all the post that is published 
);
$result = new WP_Query( $args );
$title_list[''] = "Assign a Vehicle";

if ( $result-> have_posts() ) :
while ( $result->have_posts() ) : $result->the_post();
    $title_list[get_the_ID()] = get_the_title();   
endwhile;
endif; 
wp_reset_postdata();
    
return $title_list;
}

               
         

Go to Source
Author: bigant841

MySQL count results from JOIN with where clause

I’ve got two tables.

chats:
id, name, type, deleted_at

user_chat:
id, user_id, chat_id, deleted_at

What I’m trying to do is to select a private chat with a user ID 1, where it’s the only participant in the chat, avoiding sub-queries.

What I tried:

SELECT count(user_chat.id) as count_users, chats.*
FROM chats
    LEFT OUTER JOIN user_chat on user_chat.chat_id = chats.id
WHERE chats.type = 'private'
    AND user_chat.user_id = 1
    AND user_chat.deleted_at IS NULL
    AND chats.deleted_at IS NULL
GROUP BY chats.id
HAVING count_users = 1;

With all variants of group, having, etc. with no luck. Please, advice.

Go to Source
Author: Tim Mishutin

Language setting for ‘TZD’ format in TO_CHAR (timestamp with time zone)

Which setting controls the language of ‘TZD’ or ‘TZR’ in the TO_CHAR(timestamp with time zone) function?

e.g.
select to_char(systimestamp at TIME zone ‘AMERICA/EDMONTON’, ‘TZD’) from dual;

returns the English value for TZD “MDT” (Mountain Daylight Time), which is expected as the default value.

However, I can’t find which parameter or setting to use for it to return the French value of TZD, i.e. “HNR”

  • I’ve tried adding “, ‘nls_date_language=FRENCH'” to the TO_CHAR example above, as well as altering the session parameters NLS_LANG and NLS_DATE_LANGUAGE, but to no avail.

Thanks,
Marc L.

Go to Source
Author: Marc Lalonde

Getting proper output of my SELECT clause. SQLite

I am coding a bus connection search engine. My goal is to see the time when the bus is departing, while the stop_from and stop_to names are provided.

I have created the STOP table

CREATE TABLE STOP (
ID INTEGER PRIMARY KEY,
STOP_NAME TEXT NOT NULL,
ROUTE_ID INTEGER NOT NULL
);

and the TIMETABLE table

CREATE TABLE TIMETABLE (
ID INTEGER PRIMARY KEY, 
TIME TEXT NOT NULL,
STOP_ID INTEGER NOT NULL,
FOREIGN KEY (STOP_ID) REFERENCES STOP (ID)
);

The route starts in Lidzbark Warmiński and leads via Smolajny and Dobre Miasto to Olsztyn. There are four connections per day. And I have also inserted all the possible routes from Lidzbark Warmiński to Olsztyn

INSERT INTO STOP VALUES
(1,'Lidzbark Warmiński', 1),
(2, 'Smolajny', 1),
(3, 'Dobre Miasto', 1),
(4, 'Olsztyn', 1),
(5, 'Lidzbark Warmiński', 2),
(6, 'Smolajny', 2),
(7, 'Dobre Miasto', 2),
(8, 'Lidzbark Warmiński', 3),
(9, 'Smolajny', 3),
(10, 'Smolajny', 4),
(11, 'Dobre Miasto', 4),
(12, 'Smolajny', 5),
(13, 'Olsztyn', 5),
(14, 'Dobre Miasto', 6),
(15, 'Olsztyn', 6),
(16, 'Smolajny', 7),
(17, 'Dobre Miasto', 7),
(18, 'Olsztyn', 7);

and the timetables regarding them

INSERT INTO TIMETABLE VALUES
--towards Olsztyn
(1, '08:00', 1),
(2, '12:00', 1),
(3, '15:00', 1),
(4, '19:00', 1),
(5, '08:00', 2),
(6, '12:00', 2),
(7, '15:00', 2),
(8, '19:00', 2),
(9, '08:00', 3),
(10, '12:00', 3),
(11, '15:00', 3),
(12, '19:00', 3),
(13, '08:20', 4),
(14, '12:20', 4),
(15, '15:20', 4),
(16, '19:20', 4),
(17, '08:20', 5),
(18, '12:20', 5),
(19, '15:20', 5),
(20, '19:20', 5),
(21, '08:30', 6),
(22, '12:30', 6),
(23, '15:30', 6),
(24, '19:30', 6),
(25, '08:20', 7),
(26, '12:20', 7),
(27, '15:20', 7),
(28, '19:20', 7);

I am developing under python 3.8 and this is a function with my SELECT clause

def fetch_hours(cursor, stop_from_name, stop_to_name):
    cursor.execute(
        '''SELECT T.TIME FROM TIMETABLE T
             JOIN STOP S1 ON T.STOP_ID = S1.ID 
             JOIN STOP S2 ON S2.ROUTE_ID = S1.ROUTE_ID 
             WHERE S1.STOP_NAME = ? 
             AND S2.STOP_NAME = ? ORDER BY T.TIME ASC''', 
        (stop_from_name, stop_to_name)) 
    return cursor.fetchall()

However, I have encountered some problems. For a wide range of bus stops this code doesn’t work well. Providing stop_from Smolajny and stop_to Dobre Miasto, the result is

Departures: 08:00, 08:30, 12:00, 12:30, 15:00, 15:30, 19:00, 19:30

While I would like to see only four hours. For some connections it doesn’t work at all and for some it is OK.

The desired effect is to see four departure hours for any stop_from and stop_to on this route (from Lidzbark Warmiński to Olsztyn). The reverse route is now commented, and if it would be helpful, the rest of my code can be achieved here: https://github.com/wwmarkositrawe/autobusy-backend

While looking for help,
Wishing you best regards,
marasecki

Go to Source
Author: marasecki