How to do make Where clues to compare input data with Columns - php

I want to get DATA from mysql TABLE by submit this multiple select value & compare with this columns.
http://prntscr.com/nmsmw1
http://prntscr.com/nmsnts
I followed this , but not working.
$Data=Employee::whereIn('skills', $request->skills)->get();

you can convert this sql query into laravel, So you can use FIND_IN_SET() in Laravel like as bellow query.
$data = Employee::whereRaw("find_in_set('".$request->skills."',employees.skills)")->get();

Related

get value from database in string using query builder

so in controller I am getting a value from a input form in string i.e. product_name
return $request->input('product_name');
And on the behalf of this I want to get product_id of that product from database table using query builder
return category::where('product_name',$request->input('product_name'))->get('product_id');
problem is, I am getting the value in array form but i want this value in string
//output
[{"product_id":7}]
but i want it in string like
7
please help to achieve this in single line using query builder, thanks in advance
Use the value method to get a single value:
category::where('product_name', $request->input('product_name'))
->value('product_id')
Laravel 5.8 Docs - Queries - Retrieving Results - Retrieving A Single Row / Column From A Table value
This should work:
return category::where('product_name',$request->input('product_name'))
->first()->pluck('product_id');
It looks like you want only one entry. For this you should use first() instead of get().

MySql select values of serialized column with PHP [duplicate]

How do i search from serialize field in mysql database except mysql like statement?
The data is:
a:9:{s:2:"m1";s:4:"1217";s:2:"m2";s:8:"9986-961";s:2:"m3";s:19:"1988-03-07 00:00:00";s:2:"m4";s:0:"";s:2:"m5";s:0:"";s:2:"m6";s:0:"";s:2:"m7";s:3:"104";s:2:"m8";s:6:"150000";s :2:"m9";s:18:"Ok Then, Yes It Is";}
I need the row in which the m9 value is 'Yes It Is'. I do not want to use mysql 'like' statement.
I have tried:
SELECT * FROM table WHERE field like '%Yes It Is%'
Can you please help.
Have you tried the following:
SELECT * FROM table WHERE field like '%"m9";s:18:"Ok Then, Yes It Is";%'
?
But in fact if you want to search in such data, you should simple create proper structure of your table and not to put all serialized data in one column

How to get column names from a query in IBM db2 via SQL

Is it possible to get the list column names from a query in IBM db2?
Consider a very simple example I want the column names fetched by following SQL;
select * from db.t1,db.t2 where t1.id = t2.id
Actually I know how to get column names from a a single table. But facing difficulties to get column names from such scenario.
I want the list of columns as an Array in PHP. It can be done if I just add "FETCH FIRST 1 ROW ONLY" as the end of the SQL, and run it. Then from result set I can get the columns.
But if there is no data then also I need the list of columns. How to achieve that?
Any help would be great for me.
You can use db2_num_fields() to determine the number of columns in the result set, then loop over them and call db2_field_name() to obtain the names.
You could always just do something like
describe select * from tablea, tableb

How to search for comma separated multiple values

I have created a table in MySQL in which a "skill" field has multiple comma-separated values, for instance: "PHP, JavaScript, C#".
I want to know an SQL query which will go through all values and give back a result according to the search values.
The correct MySQL function is FIND_IN_SET().
You would use it like:
SELECT * FROM USERS WHERE FIND_IN_SET('PHP', skill)>0
Where you can swap PHP out for the string you are searching for. This isn't the most efficient way to organize this data, but for smaller data sets might be fine.

How to Store Multi Select Box in php?

am having select box with multiple options, like option1,option2,option3,option4,option5.Now i want to select more than one option.
For Example: Select option1,option5,option3.and click submit.after submitting the select box need to show the selected items.
in which format to be stored in mysql and what's the exact coding to do that?please help me to get rid of this problem...
You could serialize the data in and out.
Use name[] as your name which results in an array in PHP.
$_POST['name'];
serialize($name);
//now insert into DB
Do the opposite to retrieve:
unserialize($name);
But to be honest you are better off looking at more granular methods of storing the data, rather than trying to stuff it all into one field in a database. You could take the array and loop through it storing each choice in a separate row or field.
foreach($name as $value){
//insert $value into db
}
use implode
$var = implode ( "|", $_POST['selectname']);
Try this:
http://www.aleixcortadellas.com/main/2009/03/20/492/

Categories