Select statement help needed - mysql

I am writing a query in a mysql db website and need a little help on the select statement syntax. I need to retrieve info from a database containing user input from a web-form at my site. There are a large number of over-the-road drivers who need to check in reporting their location with this form. The goal is to have a concise grid display table on the resulting web page that shows only the latest entry for all the drivers with only the 3 criteria on each row, (– name – location – date/time). The code included below does return results for all the drivers, but in the form of a long list of all entries for each driver on multiple pages instead of just updating location for each driver. It seems like I need to use “DISTINCT” and/or “LIMIT” in the string, but my attempts at this haven’t produced the desired results.
Thanks, Mike
$myquery = "select name, location, recordtime from ".$config->site_db."form_db order by recordtime DESC";

If I understand correctly you want to select the record with the highest recordtime for each name:
$myquery = "select name, location, max(recordtime) from ".$config->site_db."form_db group by name";

Related

Joining 2 tables together and using the where function based on a separate mysql query

I am building a training platform for work. I have created the requirements for a user to be trained based on a role given to them. If that role is aligned to a document it will sit against the user. I have managed to get most of the way but am struglling on the best way to finish the where statement within mysqli.
tbldocfiles is a list of my files. I am looking at docid (could be multiple files associated to the document)
tbltrainingaccess sets the roles (driver, warehouseman, customer services) and shows which role (by id) is associated to the document in docfiles.
tblusertraining is the list of users and what role they have associated to them. (driver, warehouseman, customer services).
I am listing the documents associated to the user so have thought the following is the best way:
Look at the user and how many roles he/she is allocated
Look at the roles returned in point 1 (where function)
Identify and match the documents that have the same roles as the user (Join function)
create the list, then look at the unique values for docid. (distinct value)
Example User Bri has the driver and warehouseman role.
There are 5 documents in the db, 3 of them are associated to the driver role (docid 1,2,3) and 2 of them are associated to the warehouseman role (docid 2,4) the 5th document is associayted to customerservice.
My query should do this:
List all documents associated to the roles, that are associated to the user Bri
1
2
3
2
4
Now select unique values (using docid) from the above list:
1,2,3,4.
So my answer will be a used as a count function at the end using mysql_fetch_rows
SELECT DISTINCT tbldocfiles.docid FROM tbldocfiles LEFT JOIN tbltrainingaccess ON (tbldocfiles.docid = tbltrainingaccess.docid) where groupid='1' or groupid='9'
The above code works. but i've got myself confused.
The where statement needs to be the result of a query similar to :
select * from tblusertrainingrole where userid='1' (1 will be a variable based on page selection)
the result in this would be 1, 9 which are the groupid results.
Basically any help would be appreciated! I am sure it will be simple but have burnt myself out on this for a while and most answers in here helped with joining but not the where statement (that I could find)
Thank you in advance everyone!
You can do a select statement in the where. Since it is an or statement you can use in for the results. Please replace * with the column name for the value you need. Should look like
where groupid in (select * from tblusertrainingrole where userid = '1')

Need to identify dynamic text value in selenium python

I am new to selenium webdriver python . I need to automate back end process of an e-commerce application ( order processing)
here the orders are classified to three types :
say A-type , B-type and C-type .
After successful order completion the orders will listed in an interface .
In all listed orders, its order type will mentioned like
"ORDER TYPE:A-type"
According to these three types certain scenarios will be executed. I need to identify this type. In a page there may be more than one A-type/B-type/C-type orders.
here the orders will be listing one by one will all user details along with order type. please help in this.
its html tag details:
order Type: A-type

Select ALL in SSRS

I have a table based on three drop down lists. The first is a client list, the second is a date list and the third is a stage list. The first two are single value lists. I can only allow the user to select 1 from each of those lists. The third list is a stage list. This contains the values First,Final and Release. My client has come back to me and asked if I can supply them with the ability to select all of the stages as an option. Here is the query as I have it right now. I have tried using (AnnotationDate IN (#Stage)) in place of (AnnotationDate = #Stage) but was unsuccessful. Can anyone give me a helpful hint?
SELECT AdDate, Page_ID, Status, AnnotationNumber, AnnotationBy, [Role Description], AnnotationDate, AnnotationType, BusinessUnit, ActualAgencyError, ErrorType,
AnnotationComments, TeamComments, sgkComments, PA, Client, Activity, Support, Name, BusImpact
FROM vwAgencyErrorOpen
WHERE (Client = #Client) AND (AdDate = #Job) AND (AnnotationDate = #Stage)
ORDER BY Page_ID
Change your #Stage Parameter to be multi-seletion.
Then remove the (AnnotationDate = #Stage) clause from the query.
And then set up a filter on your dataset as below:
You can then select all of your options.

How can I see full order details for each time a certain coupon code was used in magento?

We are trying to collect data on each person that used a certain coupon code "NEWCUSTOMER". We are trying to get the order details including their name, email address, and what they ordered.
Is the rule_id connected to an order in any way in the database? The magento databases don't seem to be all that friendly when you are trying to write your own mySQL statement to figure this information out.
Thanks!
This is similar to your previous question which i have also answered for you: Find the name and email address of non-members who used coupon code in Magento
The coupon code used on an order is actually a property of the order: coupon_code
It sounds from your question that you are directly querying the db, if so then you are looking for the coupon_code field in the sales_flat_order table.
Here is the sql:
SELECT `customer_firstname`, `customer_lastname`, `customer_email` FROM `sales_flat_order` WHERE `coupon_code` = 'your_awesome_coupon_code' AND `customer_group_id` = 0
Or, via magento...
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('customer_firstname')
->addAttributeToSelect('customer_lastname')
->addAttributeToSelect('customer_email')
->addAttributeToSelect('customer_group_id')
->addAttributeToSelect('coupon_code')
->addAttributeToFilter('customer_group_id', Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)
->addAttributeToFilter('coupon_code', 'NEWCUSTOMER');

MySQL: INSERT INTO with static and dynamic values mixed

I am trying to "syphon" data over from one table to another. The problem I run into is that some of the data which is going in the new table is static, other data is being copied from an existing table. Let me start by showing the query I was trying to run:
INSERT INTO current_cart
(cart_ID,
cart_PO,
cart_user,
cart_date,
cart_qty,
cart_sku,
cart_description,
cart_price,
cart_linetotal)
VALUES
('$cartID',
'$poNumberNew',
'$email',
'$lineDate',
SELECT
orderdetail_qty,
orderdetail_sku,
orderdetail_description,
orderdetail_price,
orderdetail_linetotal
FROM orderdetail
WHERE orderdetail_custemail = $email AND orderdetail_po = $poNumber)
Obviously, all the PHP variables are declared beforehand. Essentially what I have running is a shopping cart. This query would take the items from a previous order and enter them in a new shopping cart so our customer can start a new order based on a previous order.
The problem I run into is how to insert records into a table when some of the data for the record is static (cartID, poNumberNew, email and lineDate) and other information is coming out of a different table? I am hoping I can do this without creating a loop to repeat a query for however many items there were in the order the customer is duplicating... I think that would bog down our site significantly.
I've seen a myriad of awesome answers on many other web dev questions I've had in the past, I'm hoping the stackoverflow community can help me out here...
Thanks!
in a SELECT statement, you can have a column that returns an constant. For example,
INSERT INTO current_cart
(cart_ID,
cart_PO,
cart_user,
cart_date,
cart_qty,
cart_sku,
cart_description,
cart_price,
cart_linetotal)
SELECT
'$cartID',
'$poNumberNew',
'$email',
'$lineDate',
orderdetail_qty,
orderdetail_sku,
orderdetail_description,
orderdetail_price,
orderdetail_linetotal
FROM orderdetail
WHERE orderdetail_custemail = $email AND orderdetail_po = $poNumber)