mysql - How do I put all column names in a php array?
I have a table named showcase and I want the user inserting his products in this table. The point is that I would like that the user could add showcase argument like "sale" or whatever he wants. To do that I thought he could insert the showcase argument in a form and then add it like a column in the showcase table. If I don't know column names how can I show them?
EDIT
Ok, I used this code, I skipped the first column because it's the id one... It doesn't show me nothing but the part after the foreach... Do you know what could it be?
<form method="post" action="move_showcase.php">
<?php
$result = mysql_query("SELECT * FROM vetrina");
$element = mysql_fetch_assoc($result);
$value = array(array_keys($element));
$i = 0;
foreach($value as $rowname){
if($i==0){
$i++;
continue;
}
?>
<div >
<span >
<input name="rowpost[]" type="checkbox" aria-label="...">
</span>
<span id="basic-addon3">
<i aria-hidden="true">
</i>
<?php
echo $rowname;
?>
</span>
</div>
<?php
}
?>
<div >
<div >
<span >
<input type="checkbox" name="chkaddshcs">
Altra Vetrina
</span>
<input type="text" name="addrowname" placeholder="Aggiungi Vetrina">
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</form>
Answer
Solution:
MySQL has a query to show all the column names:
You can loop the return value like normal table rows.
I would recommend you to switch to PHP PDO or MySQLi, because php_mysql is outdated and insecure.
Also reading results is more powerful.