My value stored in the database looks like this ["7","8"] and i want to check if my search value is present in it for that i had used my code like this
$this->db->where_in(json_decode('tool_id'),$tool_id);
$this->db->where('status',0);
$query=$this->db->get('tbl_tools_supplied');
return $query->result();
my all values are stored like this in tool_id column here its not getting the output so is there any other way
This works for me
SELECT * FROM table_name WHERE FIND_IN_SET("7", REPLACE(REPLACE(tool_id,'[', ''),
']',''))
you can not search your id in where condition of sql query if column store data as json,but you can fetch all records and then filter out result array of mysql query by match your id.
Related
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();
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
In pg_select function the third argument is a array used to specify the column name and its value.
It works like an and condition if we give more than one key => value.
I have id column in my table I want to fetch the rows which has id value more than 1000.
How to give value in associative array in pg_select function for the above requirement.
I need answer without using pg_query function.
Unfortunately, pg_select is too simple for this. You have to write the full query one way or another.
you can using SQL:
pg_query("select * from table_name where id <1000 ");
The code:
$review = mysql_query("SELECT conceptID, MIN(nextReview) FROM userconcepts WHERE userID='$userID'");
$nrows = mysql_num_rows($review);
echo "$nrows<br />\n";
The query works when the table has such entries and returns the correct column values. However, when the table is empty, as I can confirm right now in HeidiSQL, mysql_num_rows still returns 1, but the column values are empty. (The problem still remains if the table has other values for different userIDs).
I expect this query to return the empty set sometimes during normal operations, and I want to take action based on the existence of a result, but I also want to use the result if it exists. Any idea why this code is not working as I expect it to work (I expect it to return 0 if the table is empty)?
First of all, the query has a very simple problem: you're showing the conceptID field, but not grouping by it. If you want to show a field on a SELECT that uses aggregate functions, you should show it; not doing so is an error, and will make many engines not execute your query.
That aside, whenever you have an aggregate function, and you don't group by anything (i.e., don't add a GROUP BY clause), the result is one row. Regardless of the amount of rows in the table.
The reason why is because when a SQL engine executes a query with only aggregation functions, then it returns one row. So:
select count(*)
from table
where 1 = 2
is going to return 1 row with the value 0. This is the way that all SQL engines work.
Your query is a little different:
select conceptID, MIN(nextReview)
FROM userconcepts
WHERE userID='$userID'"
In most SQL dialects, you would get an error of the from "conceptID not in group by clause" or something like that. That is, the query would have a syntax error.
MySQL supports this. It will return the minimum value of nextReview (from the rows that meet the where condition) along with an arbitrary value of conceptID (from those same rows). In this case, there are no rows, so the values will be set to NULL.
Perhaps, you want one row per conceptId. That query would be:
select conceptID, MIN(nextReview)
FROM userconcepts
WHERE userID='$userID'
group by conceptId
I am working with several csv files.
In mysql SELECT col FROM table WHERE id = '11';
It is the method where I would obtain all records where id = 11.
I am searching for php function like this SELECT column/title FROM file.csv WHERE id ='11'.
Then it may returns all records with id= '11'.
Using fgetcsv you can read in the file row wise. Simply store the rows in arrays which have the relevant search keys as index. Thus you will have an array with key 11 that has an array of rows as value.
Alternatively store the data in a memory database and query it with SQL.