Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Victor Bielski
Victor Bielski
2,325 Points

How to make dynamic content with php and MySQL?

Hello everyone,

I'm about to start on my finishing project to complete my multimedia education. I'm supposed to make my own kinda "work board", where you can add the projects you are working on at the moment. You need to be able to change the current status on the project you are working on. Something like "Design phase", "Implementing phase" and "Testing phase". That's basically what I'm going to make.

My idea is to make it with php and MySQL since I already have knowledge in those. And the projects you are adding, is going to be bootstrap 4 cards, which will be generated with PHP. So first of all. I'm kinda confused how I can make the user able to change the status of the current project. Should I make a table for each status, and somehow move the data from one table to another on button click or something like that?

Since I'm in the beginning stages of the project, I'm very open for some other ways to accomplish the project. So if you have any suggestions, like use of a CMS instead, feel free to post them.

Help is appreciated, and have a nice weekend all :)

2 Answers

Niki Molnar
Niki Molnar
25,698 Points

Hi Victor

I created something similar with php, jQuery and MySQL but I started off without jQuery and doing what you’re suggesting and having 3 or 4 columns for the different phases. I added a button on each card that when clicked would move it to the next stage, or if completed would move it back one step again.

After that was working, I wanted to be able to move a project from completed back 2 steps but had no way of doing it.

I thought of using a <select> to choose which section to move a card to but it would be time-consuming from a user experience.

I finally used the jQueryUI Sortable widget to be able to drag and drop cards to another phase column, then used php via AJAX to update the database.

Good luck!

Niki

Instead of having separate tables for different statuses (this seems to me to be extremely inefficient), I would have a column in your table for projects called "status". Create a <select> or a set of radio buttons on each project for the user to change the project status, and create a function that will receive the form value when submitted and then update the "status" column for the project. Something like this should suffice:

//getting your data from the form
if ($_SERVER['request_method'] == 'POST')) {
    $project_id = filter_input('input_post', 'project_id', FILTER_SANITIZE_NUMBER_INT);
    $status = filter_input('input_post', 'status', FILTER_SANITIZE_STRING);
}

//function to update the status column in your projects table
function update_status($status, $project_id) {
    //database connection here
    $sql = "UPDATE projects SET status = ?
                WHERE project_id = ?";
    $databaseObject->prepare($sql);
    $databaseObject->bindParam(1, $status, PDO::PARAM_STR);
    $databaseObject->bindParam(2, $project_id, PDO::PARAM_INT);
    if ($databaseObject->execute()) {
        //redirection, close connection, whatever you want to do
    } else {
        echo "Could not update records";
        exit;
    }
}

Apologies if the syntax is not perfect for that function, but it should still give you an idea. So when the user changes the status on the client end, a PHP file should receive the new status from a form and use it to run an UPDATE query on the database. Hopefully this makes sense and helps!