2

This code was given to me by a friend and works perfectly, however in my system it Array to string conversion in C:\wamp\www\web2\database.php on line 90 and on line 91

     function edit($table, $id)
        {
             $query = "SELECT DISTINCT  `COLUMN_NAME` 
            FROM  `INFORMATION_SCHEMA`.`COLUMNS` 
            WHERE  `TABLE_NAME` =  '$table'";

      echo "<form method='post' action=''>";

            $header = $this->dbLocalhost->query($query);

            foreach($header as $data) {
                echo "<p>";
    90.         echo "".$data.": ";
    91.         echo "<input type='text' name=".$data." />";    
                echo "</p>";
            }

            echo "<input type='submit' name='Insert' />";

            echo "</form>";
}

sorry to ask, as I have the irritating feeling its very simple. Thanks

4

2 回答 2

2

谢谢我将 $data 更改为 $data['COLUMN_NAME'] 而不使用 print_r($data) 来提供所需的结果。

于 2012-11-16T02:45:04.447 回答
0

尝试这个

$q = "SELECT DISTINCT  `COLUMN_NAME` FROM  `INFORMATION_SCHEMA`.`COLUMNS` WHERE  `TABLE_NAME` =  '".$table."'";
$cols = mysql_query($q);
while ($col = mysql_fetch_object($cols)) {
    echo "<p>";
    echo ucfirst($col->COLUMN_NAME);
    echo "<input type='text' name=".$col->COLUMN_NAME." />";    
    echo "</p>";
}

输出将类似于

<p>Id<input type="text" name="id"></p>
<p>Name<input type="text" name="name"></p><!--and more-->
于 2012-11-16T02:46:06.900 回答