public function index()
{
$yek = $this->input->post("KEY");
$cek = $this->m_user->get('KEY' => $yek)->num_rows();//line 14
$response = array();
if ($cek > 1)
{
$list = $this->m_masalah->jenis();
}
foreach ($list as $key ) {
$arr = array();
$arr['ID_MASALAH'] = $key['ID_MASALAH'];
$arr['MASALAH'] = $key['MASALAH'];
$arr['JENIS'] = $key['JENIS'];
array_push($response, $arr);
}
echo $json_response = json_encode($response);
}
this is my erorr
Parse error: syntax error, unexpected '=>'
(T_DOUBLE_ARROW), expecting ',' or ')' in
E:\xampp\htdocs\sengketa_dpbt\application\controllers\Masalah.php on line 14
The => symbol is used for assigning array elements, but you didn't declare it as an array here. Just make this change:
$cek = $this->m_user->get(array('KEY' => $yek))->num_rows();
Related
I am using this package for my laravel application for the mongodb database: https://github.com/jenssegers/laravel-mongodb
Now, I have and id column which contain integer value like: 32312794972256
Now, I am searching like this:
$filtered = array_filter( $request->all());
$trimmed_array = array_map('trim', $filtered);
$new_arr = [];
foreach( $trimmed_array as $k => $v ) {
if( $k !== 'page' && $k !== 'projectToken' && $k !== 'userId' ) {
if( is_numeric( $v) ) {
$v = (int) $v;
}
$new_arr[] = [$k, 'LIKE', '%'. $v .'%' ];
}
}
Log::info( $new_arr );
$projectToken = $request->input('projectToken');
$userId = $request->input('userId');
$this->set_connection( $projectToken, $userId );
$get_project_id = DB::connection('mysql')->table('projects')->where('token', $projectToken )->get(['id_project'])->first();
$collection = 'products_' . $get_project_id->id_project;
$collection = 'products_103';
if(count($new_arr)) {
$search = DB::connection('mongodb')->collection( $collection )->where($new_arr)->paginate(100);
} else {
$search = DB::connection('mongodb')->collection( $collection )->paginate(100);
}
But above search query is not showing any result for this integer search. Do you know why?
public function goesWellWith(Request $request)
{
$seo_url = $request->seo_url;
$product = $this->product->getByAny('seo_url',$request->seo_url)->first();
$categories = $this->product->getProductCategories($product->id);
$category_ids = [];
$products = [];
if(count($categories) > 0){
$category_ids = array_column($categories, 'term_id');
}
if(count($category_ids) > 0){
$get_fillter_product = $this->product->getProductByFilter([
'recommended' => "on"
],$category_ids);
foreach($get_fillter_product as $single_product){
$categoryProductList = [
'title' => $single_product->title,
'sub_title' => $single_product->sub_title,
'first_image' => $single_product->first_image?$single_product->first_image->full_size_directory: null,
'second_image' => $single_product->second_image?$single_product->second_image->full_size_directory: null,
'seo_url' => $single_product->seo_url
];
$category_ids [] = $categoryProductList;
}
}
return response()->json(compact('category_ids'));
}
//
-
List item
when i hit the url in insomnia to check i got this ErrorException array_column() expects parameter 1 to be array, object given//
i got the error in this line of code
if(count($categories) > 0){
$category_ids = array_column($categories, 'term_id');
}
Try change your code from this
$categories = $this->product->getProductCategories($product->id);
To
$categories = $this->product->getProductCategories($product->id)->toArray();
I'm trying to create a command that lets me write to a json file. I'm able to do that but I'm struggling to get some values out of my if statement.
Here is my code
foreach($update as $key => $value)
{
$name = '';
$hours = '';
if($value != 0)
{
$name = $key;
$hours = $value;
}
$array = [
$name => $hours
]
}
but when I run my code I get a blank $name and a blank $hours
You're always getting last record. Also, you can ignore redundant values in your data.
I guess these lines can help you
foreach($update as $key => $value)
{
if ($value == 0) {
continue;
}
$name = $key;
$hours = $value;
$array[$name] = $hours;
}
maybe these lines help you
$update = [1 => 'a', 2 => 'b', 3 => 'c'];
foreach ($update as $key => $value) {
if ($value !== 0) {
$name = $key;
$hours = $value;
$array[$name] = $hours; // $array[]= [$name=>$hours];
}
}
note : if $update array values contain strings will return true at all because at php
('a' == 0) will return true for that i used !==
I am importing CSV file to Laravel controller and insert data into two tables, but I got error-
array_combine() Both parameters should have an equal number of elements
function csvToArray ($filename = '', $delimiter = ',')
{
If (! file_exists ($filename) ||!is_readable($filename))
return false;
$header = null;
$data = array ();
if (($handle = fopen ($filename,'r')) !== false)
{
while (($row = fgetcsv($handle, 300000, $delimiter)) !== false)
{
if (!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
public function importCsv()
{
$file = public_path('file/city_master.csv');
$customerArr_data = $this->csvToArray($file);
for ($i = 0; $i < count($customerArr_data); $i++)
{
dd($customerArr_data);
}
return 'not in array';
}
Please try using array_merge() instead. Hope this helps
I have a trouble about phpmyadmin of laravel
I want to update the data from the view on the db via controller but I get an error occurred
// save all seats
foreach ($request->all() as $key => $param) {
if ($key === '_token') continue;
$data = explode('-', $key);
$bs = new BookedSeat();
$bs->booking_id = $booking->id;
$bs->day_id = str_replace('c', '', $data[0]);
$bs->table_id = str_replace('t', '', $data[1]);
$bs->number = 0;
$bs->status = 'requested';
$bs->save();
}
its an error when i try update data
its my db
Updated
// save all seats
foreach ($request->all() as $key => $param) {
if ($key === '_token') continue;
$data = explode('-', $key);
$bs = new BookedSeat();
$bs->booking_id = $booking->id;
$day = DB::table('days')->where('name',$data[0])->get();
$bs->day_id = $day->id;
$bs->table_id = str_replace('t', '', $data[1]);
$bs->number = 0;
$bs->status = 'requested';
$bs->save();
}