firstOrNew where MONTH and YEAR laravel [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
$matchThese = array('product_id' => 8789, 'MONTH(date_created)' => '04');
$result = ExpiryPrepayment::firstOrNew($matchThese);
$result->payment_status = 1;
$result->save();
***====>'MONTH(date_created)' => '04'***
Help me get condition only month or year in column date_created

Why are you sending an array at a firstornew? This is basically a string that you are building an array with in the eloquent. Inserting an array will not work. Really the product_id should be a unique so you only need that value in your where.
So it would be something like this...
firstOrNew(['product_id' => $product_id]);
$product_id being the variable of the unique id.
Then if you have tons of products to add just loop over the array of product ids and it will either make a new row at your save or update the product when it finds it first.

Related

How to get rating value (WordPress) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
$rating = $rowsRaing;
Array
(
[0] => stdClass Object
(
[ratting] => 2.5
)
)
I want rating value.
I want user average number of ratting help me
Thanks
Your query should be
$rowsRaing = $wpdb->get_results("select avg(ratting) as rating from tablename where id='".$_REQUEST['id']."'");
$rat=$rowsRaing;
$RatingVal = $rat[0]->rating;
By using this variable you get the avg number of ratting
"$RatingVal"
It's var of object inside array, so:
$yourRatingValue = $rat[0]->rating;

How to get sum for the values inside specific column? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a table "selled" which has three column id, qty, code how to sum all the values in qty column where code = X, I know how to count the number of rows in this column but I want to get the sum of the values inside these rows.
I am sorry guys i am still beginner and i really appreciate it ,This is the code i am using and it still not working
$query="SELECT SUM (qty) as sum_of_qty from selled WHERE code='$code'";
$result=mysqli_query($connection,$query);
$row=mysqli_fetch_assoc($result);
echo $row['sum_of_qty'];
Use the SUM function. Docs:
https://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_sum
SELECT SUM(qty) as sum_of_qty FROM selled WHERE code = x

How to count some number on a while loop and order them from the biggest number? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a shop, and in seller section I want to make a top8 sellers.
Accounts are saved on another table, users on another table.
I want to get users, and count their sold data, and order them like top 8 list goes.
How can I do that, what I need? I have no idea at all.
The database has columns of accounts data and their price, so I need to count the price first.
First of all you need to select all orders you have.
After that, you loop through them and sum their orders by user id:
$sums = array();
foreach($orders as $order){
if(!isset($sums))
$sums[$order['id_user']] = 0;
$sums[$order['id_user']] += $order['order_value'];
// order_value is sum of total products - meaning order value - I', not
}
Now, you have $sums array filled with total spent by user_id.
Now all you have to do, is to sort them usint arsort ( http://php.net/manual/en/array.sorting.php )
Now you have array, where first 8 rows are top buyers.

pulling data out of mysql creating array with array structure [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a MySql database with three columns: skp, date and usr. For each skp and date pair there are several usr(s). Is there a query that will pull the data out with the following array structure:
array[i]['skp']
array[i]['date']
array[i]['usr'][j]
I'm wondering if somehow using a group by would work?
Use GROUP_CONCAT.
SELECT skp, date, GROUP_CONCAT('usr') AS usr
FROM yourTable
GROUP BY skp, date
Then when retrieving, you can split the usr column into an array.
$array = ();
while ($row = mysqli_fetch_assoc($result)) {
$row['usr'] = explode(',', $row['usr']);
$array[] = $row;
}

The database returns only the first row instead of column [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to obtain a column name EmailId from the table named Users. But it returns only the first string and nothing else?
PHP:
$sql="SELECT EmailId FROM Users;";
$result =mysqli_query($conn,$sql);
$col=mysqli_fetch_array($result);
The database has 3 email-ids but count($col) returns only 1. Why so?
Thanks in advance.
The database has 3 email-ids but count($col) returns only 1. Why so?
Because
$col=mysqli_fetch_array($result);
only fetch the first row according to the internal pointer of the dataset, and therefore
count($col)
returns 1 because $col is an array having 1 item.

Categories