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 6 years ago.
Improve this question
I have this code to output the value in table i used group by to
group the same item code but serial does not show it only show
onevalue the 123321. The output should be 123321,4354
$invoicequery=mysqli_query($link,"Select SUM(INVOICE_ITEM_QTY_MX),INVOICE_ID_MX,INVOICE_ITEM_UPRICE_MX,INVOICE_ITEM_AMOUNT_MX,INVOICE_ITEM_SERIAL_MX,INVOICE_ITEM_DESC_MX,INVOICE_ITEM_CODE_MX from invoice WHERE BRANCH_CODE_MX='".$display_branchcode."'
and INVOICE_NO_MX='".$invoicecode."' GROUP BY INVOICE_ITEM_CODE_MX");
while($row=mysqli_fetch_array($invoicequery))
{
$invoiceid=$row["INVOICE_ID_MX"];
$itemcode=$row["INVOICE_ITEM_CODE_MX"];
$itemquantity=$row['SUM(INVOICE_ITEM_QTY_MX)'];
$unitprice=$row["INVOICE_ITEM_UPRICE_MX"];
$amount=$row["INVOICE_ITEM_AMOUNT_MX"];
$serialimei=$row["INVOICE_ITEM_SERIAL_MX"];
$itemdescription=$row["INVOICE_ITEM_DESC_MX"];
}
Ouput
In Database
It sounds like you are looking for MYSQL's GROUP_CONCAT() function method. Simply wrap the column name you wish to have returned as a comma separated list with that function like you have used MAX().
Example:
SELECT student_name,
GROUP_CONCAT(test_score)
FROM student
GROUP BY student_name;
This will return, for example,
student_name | test_score
Becky C. | 80, 77, 95
Note that this value will be truncated according to your db's group_concat_max_len setting.
Related
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 3 years ago.
Improve this question
I want to get values from the other rows by selecting a specifc text from the quotes from items row
Image:
I tried all the ways I've know but nothing of them working.. example
$this->f3->get('DB')->exec('select tops.id, tops.name, tops.img from tops where tops.items = 1 ');
So what I want I want to select that "1" or "2" from items row ( check the image )
If the row you show in the image is an example of what you are attempting to select, then the SQL string you should be using would be:
'select tops.id, tops.name, tops.img from tops where (tops.items like \'%"1":%\' or tops.items like \'%"2":%\');'
This will select rows where the tops.items column contains either "1": or "2":. If you are trying to match something else, then please try to be a bit clearer in your question.
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 5 years ago.
Improve this question
two columns
user_id purchase_item
1 watch
1 TV
2 watch
2 fridge
2 Toys
when i use distinct comand in sql
same as it is show data but i want to following
user_id:1
purchase_item:watch
tv
user_id:2
purchase_item:watch
fridge
Toys
means i want user id print only one time so how it is possible in php
plz help me and tell coding please
If you want to do it completely in Mysql you can use aggregation to get items as comma separated list per user
select user_id, group_concat(purchase_item) purchase_item
from table
group by user_id
this will give you results like
user_id purchase_item
1 watch,TV
2 watch,fridge,Toys
Also note using group_concat the result is truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of 1024. The value can be set higher, although the effective maximum length of the return value is constrained by the value of max_allowed_packet
But its better if you do this in php just get the ordered results and apply your logic to show user_id only once for multiple purchase_item related to that user
select * from table order by user_id asc
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 7 years ago.
Improve this question
How do I write a query that takes a list of group ids (could be 1, could be 10, etc) and gets the users who are not in ANY of those groups?
We are using Doctrine, but we can't even figure out how to do it in raw SQL.
It's okay to have PHP generate part of the query if we need to do multiple joins/conditions etc based on how many ids are provided.
If my general assumptions about your table structure are correct, I believe something like this should work:
SELECT *
FROM users
WHERE user_id NOT IN (
SELECT DISTINCT user_id
FROM user_groups
WHERE group_id IN ([your group list])
);
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 8 years ago.
Improve this question
I'm having trouble with copying data from a table with the same structure to another table with the same first column. I have 2 tables. One is STANDARD, the other one is called W2.
I then choose a name, for example Test.
I want to copy the values except for the name from the STANDARD table into the W2 table. So replace those values. As you can see the values of Test are different in the W2 table. I want to replace those values with the values from STANDARD.
STANDARD:
W3:
Can someone please help me out?
Try this
Update w2 set
Maandag = (SELECT Maandag From STANDARD a where w2.id = a.id),
Dinsdag = (SELECT Dinsdag From STANDARD a where w2.id = a.id)
Etc....
Where w2.id = 'test'
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 8 years ago.
Improve this question
I have been trying to print out data from a database table in custom order like for example..
I have a table and that have alot rows and have one column as listing_type which have values like Gold,Premium,Silver,Free etc for each row..! so how I would be able to print the data from fetched array in order like at first it should echo all Gold and then Premium and then Silver and then Free etc like..!
Any help would be appreciated..Thanks waiting for your reply.!
Use an ORDER BY clause in your MySQL query like this:
SELECT *
FROM `table`
ORDER BY FIELD(`listing_type`, 'Gold', 'Premium', 'Silver', 'Free')
The MySQL function FIELD() returns the position of str in the given strings. With this, you can create a custom order to sort your results on.
In Mysql query you can easily order results by using field() function,so returned results will be ordered in way where listing_type is gold first then premium then silver results then free
select *
from your_table
order by field(listing_type,'Gold','premium','Silver','Free' )