简体   繁体   English

从数据库到可编辑表单的数组

[英]Array from database to editable form

I want to make a form where I can edit information from an array I get from my database.我想制作一个表单,我可以在其中编辑从我的数据库中获取的数组中的信息。 And then put them in a form with strings so I can edit the values of each category from the database and then send the changed information to the database.然后将它们放在带有字符串的表单中,以便我可以编辑数据库中每个类别的值,然后将更改后的信息发送到数据库。 When I use this command当我使用这个命令时

$db = new PDO('mysql:host=mariadb.spectrogon.local;dbname=gitter;charset=utf8', 'gitter_in', 'gitter_in');
$sql = "call hämta_artikel_info('715.702.930')";
$result = $db->query($sql);
$printable = $result->fetchAll();
print_r($printable);

I get the following array back我得到以下数组

     (
        [artikel_nr] => 715.702.930
        [0] => 715.702.930
        [points] => 50x50 5 
        [1] => 50x50 5 
        [points2] => 50x50 5 
        [2] => 50x50 5 
        [scale] => 1 + 0.75
        [3] => 1 + 0.75
        [energy] => 70
        [4] => 70
        [value] => 5.000
        [5] => 5.000
        [nollan] =>
        [6] =>
        [approved_from] =>
        [7] =>
        [approved_to] =>
        [8] =>
    )

Now I would like to put all the info I've got from this array and put it in a form.现在我想把我从这个数组中得到的所有信息放在一个表单中。 Then I would be able to edit that information然后我就可以编辑该信息

The following SQL: " call hämta_artikel_info(715.702.930)" as far as I know should be a select procedure以下 SQL: " call hämta_artikel_info(715.702.930)"据我所知应该是一个select过程

My full code atm.我的完整代码自动取款机。

    <?php

echo "test";

error_reporting(E_All);
error_reporting(E_ERROR | E_WARNING | E_PARSE);



$db = mysqli_connect('mysql:host=mariadb.spectrogon.local;dbname=gitter;charset=utf8', 'gitter_in', 'gitter_in');
$connection = new Connection;
$db = $connection->openConnection();

$stmt = $db->prepare("call hämta_artikel_info('715.702.930')");
$stmt->execute();
print_r($stmt);



echo "
    while($results = $stmt->fetch()){  
    <form name='form' method='post' action=''>
    <tbody>
    <tr>
    <td><input type='text' name='id' readonly class='form-control-plaintext' value=" . $results['artikel_nr'] ."></td>
<td><input type='submit' name='update' value='Update' class='form-control'></td>";



 if(isset($_POST['update']))
{    
    $var= $_POST['var'];
    if(empty($var){
   echo"variable is empty ";
}

    else {    
        $stmt = $db->prepare("UPDATE table_name SET col_name='" .$var. "'");
}
 $stmt->execute();
        @header("Location: stackoverflow.php");
    }
}


?> 

Keep in mind that I'm very new to programming so would really appreciate detailed explanations.请记住,我对编程非常陌生,因此非常感谢详细的解释。

put foreach loop like 像这样放foreach循环

foreach($printable as $data) {
 echo $printabel->username;

}

define every thing alone $printable->your database fields here; 在这里定义每件事$printable->your database fields here;

$result = $stmt->get_result();
echo "<form name='form' method='post' action =''>
         <tbody>";
     while ($row = $result->fetch_assoc()) {?>    
        <td>
            <input type='text' name='id' readonly class='form-control-plaintext' value="<?php echo $row['artikel_nr'];?>">
        </td>

    <?php}
    echo "<td>
            <input type='submit' name='update' value='Update' class='form-control'>
        </td>
    </tbody>
</form>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM