html table and php

Javascript coding ..

Moderators: macek, egami, gesf

Post Reply
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: html table and php

Post by seandisanti » Tue Nov 27, 2012 11:35 am

You don't want to use javascript for that, keep all of your logic and processing server side. The following code isn't tested because i didn't want to create a table, but it should work as is.

Code: Select all

 // assume connection already made
    if (! isset($_POST)) { //not responding to form, must draw it
        echo '<form id="view_admin" action="' . $_SERVER['SCRIPT_NAME'] . '" method="post">';
        echo '<table>';
        echo '<tr>';
        echo '<th>ID</th>';
        echo '<th>Column 1</th>';
        echo '<th>Status</th>';
        echo '<th>Edit</th>';
        while ($row=mysql_fetch_assoc($result)){
            $theRow = '<tr>';
            $theRow .= '<td><input type="text" disabled="disabled" value="' . $row['id'] . '" name="id"></td>';
            $theRow .= '<td><input type="text" disabled="disabled" value="' . $row['column1'] . '" name="column1"></td>';
            $theRow .= '<td><input type="text" disabled="disabled" value="' . $row['status'] . '" name="status"></td>';
            $theRow .= '<td><input type="submit" name="reject" /><br /><input type="submit" name="approve" /></td>';
            $theRow .= '</tr>';
            echo $theRow;
        echo '</table></form>'
    } else { //responding to form
        if (isset($_POST['approve'])){ //it's an approval
            $sql = "UPDATE main SET status='APPROVED' WHERE id =" . $_POST['id'];
        } else {
            $sql = "UPDATE main SET status='REFUSED' WHERE id =" . $_POST['id'];
    echo mysql_affected_rows() . ' rows updated.';

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests