What's new

Welcome to xCrud Community - Data Management and extended PHP CRUD

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Default value using “relation”

mungle

New member
Joined
Dec 9, 2021
Messages
11
Reaction score
2
Points
3
Location
Dubai
Hello,
I need to set a default value in a field that uses “relation” function. “pass_default” function doesn’t works.
Any suggestions?
 
Last edited:

DaDo

Administrator
Staff member
Joined
Dec 1, 2021
Messages
108
Reaction score
23
Points
18
Hello,
I need to set a default value in a field that uses “relation” function. “pass_var” function doesn’t works.
Any suggestions?
Explain what you need ...
 

mungle

New member
Joined
Dec 9, 2021
Messages
11
Reaction score
2
Points
3
Location
Dubai
Ok... in my php file I have:

$xcrud->relation('user_who_add_the_data', 'user_table', 'user_id', 'user_name', '', '', false);
This will provide me a dropdown list of users name from my users table.
I want to add as default value in the user_who_add_the_data field the current logged in user for which I stored the name in the $logged_user_name variable
I tried to use:
$xcrud->pass_default('user_who_add_the_data', $logged_user_name);
but this doesn't works.
 

DaDo

Administrator
Staff member
Joined
Dec 1, 2021
Messages
108
Reaction score
23
Points
18
Ok... in my php file I have:

$xcrud->relation('user_who_add_the_data', 'user_table', 'user_id', 'user_name', '', '', false);
This will provide me a dropdown list of users name from my users table.
I want to add as default value in the user_who_add_the_data field the current logged in user for which I stored the name in the $logged_user_name variable
I tried to use:
$xcrud->pass_default('user_who_add_the_data', $logged_user_name);
but this doesn't works.
pass_default if valid to use post on the custom function I will raccomand you to create subselect to extract data you need and pass as variable for example : $xcrud->subselect('logged_user',"SELECT logged as logged from ... where id = $variable"); extract this data maybe return logged from query and pass on relation
 

mungle

New member
Joined
Dec 9, 2021
Messages
11
Reaction score
2
Points
3
Location
Dubai
Hi!
Relation wasn't useful to achieve what I need. I didn't really get your suggestion as subselect only add columns data and not field, right?
Anyway I solved using:
PHP:
$xcrud->pass_default('user_who_add_the_data', $_SESSION['logged_user_name']);
 
Top Bottom