0

My main issue that I am running into is basically this:

I have a while loop that generates results from a query. With the results that have been generated, I want the ability to update the table the original query was from.

The query produces the expected results, but the table is not being updated when I click the REMOVE button. I am also trying to find a solution for the results to be updated after the UPDATE query executes...

<?php
    $sql = "SELECT * FROM vehicles WHERE sold='n' ORDER BY year DESC";

    $query = mysql_query($sql);


    while ($row = mysql_fetch_array($query)) { 

    echo 
    "       
        <tr>
            <td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['year'],"</td>
            <td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['make'],"</td>
            <td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['model'],"</td>
            <td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'><input type='submit' name='remove' value='REMOVE' style='background-color:#C33;color:white;padding:10px;border-radius:5px;width:70px'/></td>
        </tr>";

    if(isset($_POST['remove'])){
        $removeSql = "UPDATE `table`.`vehicles` SET `display`='0' WHERE `vin`='{$row['vin']}'";
        mysql_query($removeSql) or die('check that code dummy');
    }

    }
    mysql_close($connection);
?>
4

1 に答える 1

0

これは送信ボタンです。フォーム タグがないと機能しません。このようにすることはできません。

別のページにを記述し、を使用してそのページとそのページremove codeを変換してsubmit button渡すnormal buttonことができます。vin idclickbuttoncallajax

または、ajaxそのページ自体でわからない場合は、次のようにします。

<?php
$sql = "SELECT * FROM vehicles WHERE sold='n' ORDER BY year DESC";

$query = mysql_query($sql);


while ($row = mysql_fetch_array($query)) { 

echo 
"       
    <tr>
        <td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['year'],"</td>
        <td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['make'],"</td>
        <td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>",$row['model'],"</td>
        <td style='border-bottom-style:dotted;padding-top:10px;padding-bottom:10px;font-size:.9em'>
        <form action="" method="POST">
            <input type="hidden" name="vin_id" value="<?php echo $row['vin']; ?>">
            <input type='submit' name='remove' value='REMOVE' style='background-color:#C33;color:white;padding:10px;border-radius:5px;width:70px'/>
        </form></td>
    </tr>";

}

if(isset($_POST['remove'])){
    $removeSql = "UPDATE `table`.`vehicles` SET `display`='0' WHERE `vin`='".$_POST['vin_id']."'";
    mysql_query($removeSql) or die('check that code dummy');
}

mysql_close($connection);
?>
于 2013-03-22T03:22:18.863 に答える