We help IT Professionals succeed at work.
Get Started

Perl/cgi DBI to mysql database select query with parameter

Dalexan
Dalexan asked
on
1,259 Views
Last Modified: 2013-12-25
Just cracked open some perl/cgi on my server and I would like some help coding a simple cgi script that will select some data and return the results to an html page.

Below is the select query:

SELECT order_item.odi_item_ref_id AS ItemName, Count(order_item.odi_item_ref_id) AS ItemCount
FROM (salesagents INNER JOIN (order_item INNER JOIN order_header ON order_item.ord_id = order_header.ord_id) ON salesagents.agent_id = order_header.usr_id) INNER JOIN item_master ON order_item.item_id = item_master.item_id
WHERE (((order_header.ord_status_id)="C") AND ((order_header.ord_confirm_date)>Date()) AND ((salesagents.agent_id)=10051) AND ((item_master.btClub)<>0))
GROUP BY order_item.odi_item_ref_id
ORDER BY Count(order_item.odi_item_ref_id) DESC;

Open in new window


I want the code in the cgi to connect to my mysql database via dbi using the below credentials:
server: 192.168.1.251
user: test
pass: test1234

The cgi will need to accept a user parameter which will be passed into the select query to the field salesagents.agent_id. so the cgi call should look like 192.168.1.250/cgi-bin/report.cgi&agentid=xxxx where xxxx is the agent_id passed to the select in code. Also I'm not sure how to handle the Date() function criteria in the sql within the cgi select.

Please help with the code needed to get this done and return the resultset of the query back to the page.
Comment
Watch Question
This problem has been solved!
Unlock 4 Answers and 23 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE