Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8646901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:55:55+00:00 2026-06-12T12:55:55+00:00

Im pretty new to PHP, basic level at MySQL and so/so at HTML and

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:55:56+00:00Added an answer on June 12, 2026 at 12:55 pm

    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…

    <?php
    $db = new PDO('mysql:dbname=your-database-name;host=localhost', $username, $password);
    $sql = $db->execute("SELECT `name` FROM `organizations` ORDER BY `name` ASC");
    ?>
    <form id="user_form" action="" method="get">
        <fieldset>
            <select name="name">
            <?php <?php while ($row = $sql->fetch(PDO::FETCH_OBJ)): ?>
                <option value="<?php echo $row->name; ?>"><?php echo $row->name; ?></option>
            <?php endwhile; ?>
            </select>
            <select name="days">
                <option value="30">30</option>
                <option value="60">60</option>
                <option value="90">90</option>
            </select>
            <input type="submit" name="submit" value="submit">
        </fieldset>
    </form>
    
    <?php 
    if(isset($_GET['days']) && isset($_GET['name'])):
        $days = $_GET['days'];
            $name = $_GET['name'];
    
            $sql = $db->prepare('SELECT tickets.ref AS `ticket_number`
              , concat_ws(' ', people.first_name, people.last_name) AS `username`
              , DATE_FORMAT(tickets.date_created, get_format(DATE, 'EUR')) AS `datetime`
              , left(tickets.subject, 80) AS `subject`
              , sec_to_time(tickets.total_to_first_reply) AS `first_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 :days DAY)
              AND organizations.name = :name
            GROUP BY
              tickets.ref
            ORDER BY
             `Date/Time`');
    
        $sql->bindParam('days', $days);
        $sql->bindParam('name', $name);
        $sql->execute();
        /*
        It looks like your data could be considered tabular, so we can make a table and drop the results in place...
        */
        ?>
        <table cellpadding="0" cellspacing="0">
            <tbody>
                <tr>
                    <th>Ticket Number</th>
                    <th>User Name</th>
                    <th>Date/Time</th>
                    <th>Subject</th>
                    <th>Time 1st Response</th>
                    <th>Total Wait</th>
                    <th>Message</th>
                </tr>
                <?php while ($row = $sql->fetch(PDO::FETCH_OBJ)): ?>
                <tr>
                    <td><?php echo $row->ticket_number; ?></td>
                    <td><?php echo $row->username; ?></td>
                    <td><?php echo $row->datetime; ?></td>
                    <td><?php echo $row->subject; ?></td>
                    <td><?php echo $row->first_response; ?></td>
                    <td><?php echo $row->total_wait; ?></td>
                    <td><?php echo $row->message; ?></td>
                </tr>
                <?php endwhile; ?>
            </tbody>
         </table>
    <?php endif; ?>
    

    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 Name would 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to PHP and have a String which contains an HTML page.
I'm still pretty new to php and mysql, I've build a basic CMS for
I am new to PHP and MYSQL so this should be a pretty basic
I am somewhat new to PHP and MySQL, and have just setup a basic
I am pretty new to PHP and MySQL and I just can't figure this
I've done a fair bit of mysql php programming but am pretty new to
I am writing a pretty basic php app and have created a pretty big
I'm pretty new to php, and for that matter server scripting in general (so
I am pretty new to php, but I am learning! I have a simple
This is probably pretty basic, but I'm a beginner in PHP - I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.