Im pretty new to PHP, basic level at MySQL and so/so at HTML and ASP. In short, I have a MySQL database that I have built a SQL query that returns the results I want in MySQL.
What I am trying to learn to do, is build a web page that will:
- Pull all known “organizations.name” from the database into a dropdown to select one. (Shown in my query where I want to put the variable as VARIABLENAME)
- Have a dropdown with a selection fo days 30 Days, 60 Days, 180 days etc. (Shown in my query as to where that needs to go as VARIABLEDAYS)
Basically, Im trying to make something that looks like this https://i.stack.imgur.com/k5sv0.jpg
And also has the relevant look on the output (Im struggling with getting the message portion of the formatting to dump below the other fields, rather than alongside).
Here is my MySQL query.
SELECT tickets.ref AS `Ticket Number`
, concat_ws(' ', people.first_name, people.last_name) AS `User Name`
, DATE_FORMAT(tickets.date_created, get_format(DATE, 'EUR')) AS `Date/Time`
, left(tickets.subject, 80) AS Subject
, sec_to_time(tickets.total_to_first_reply) AS `Time 1st Response`
, sec_to_time(tickets.total_user_waiting) AS `Total Wait`
, mycleanup (left(tickets_messages.message, 250)) AS Message
FROM
tickets
INNER JOIN organizations
ON tickets.organization_id = organizations.id
INNER JOIN people
ON tickets.person_id = people.id AND people.organization_id = organizations.id
INNER JOIN tickets_messages
ON tickets_messages.ticket_id = tickets.id AND tickets_messages.person_id = people.id
WHERE
tickets.date_created > date_sub(now(), INTERVAL VARIABLEDAYS DAY)
AND organizations.name = VARIABLENAME
GROUP BY
tickets.ref
ORDER BY
`Date/Time`
As I say, this one is a bit of a mix as I need help with:
- How to change my Query to a PHP statement, along with making VARIABLEDAYS and VARIABLENAME, things that are pulled in from the web form.
- How to make the inital Web form, and specifically, make it pull the data into the VARIABLENAME dropbox, so that its a pull down list.
- How to get my PHP form to connect to a MySQL database correctly (so far everything Ive tried incuding design packages, connect ok to make the form.. but dont do anything when on the server.. and I have changed the connection to LOCALHOST and I know PHP works fine on the server)
So anyone who wants to take a shot at helping me with any of those bits, or recommending something that I could use to generate those easily, without having to take a course in every single bit.. it would be much appreciated.
Thanks
Will
A bit heavy on expectations here, sir. The best answer I can give you is a basic example and pointing to the php.net manual.
You say you’re basic level mysql? Ok then, running the queries to pull the data is no problem then. All you need to know is how to use PHP to communicate with the database, right? Look into PDO
That being said, the succinct and accurate answer to this question is that you can’t just have someone explain the whole lot in one set. You should start with some tutorials, or examine some existing code to get an idea of how it all works. Stack Overflow is a good resource for specifics, but not necessarily for a question like this unless it happens to be seen by someone very bored with lots of time to write a huge tutorial before the question gets voted closed.
EDIT
obviously you enter your correct database credentials here…
Of course all of this is untested and ultimately a free helping hand, so my guarantees are limited. It should point you in an acceptable direction for a procedural patch.
Take notice I changed your query result names because – though I don’t actually know about this – I don’t think it’s a good idea to use spaces or characters in object names. (ex: SELECT name AS
User Namewould mean you access that object as $row->User Name… see the problem there?)Plus, you should be selecting organization by id, not name. Since I don’t know the structure of that table, I just use name as you indicate. If you want to switch to id, change the organization select to also include id and echo the id in the value portion of the organization select menu.
Aside that I think I am done here. I need to consider actually having a life sometime.
Good luck still.