2021年2月7日星期日

how to make a form if you do not how much inputs you have?

I will try to make my question as easy as I can explained.

let say there is a table named foods in our database the user inserts as much he wants in this table

id-------name  1--------apple  2-------orange  3-------water  

....etc and in this table there is a column for order called order

id-------name-------order  1--------apple-------10  2-------orange-------20  3-------water--------30  

so, the user insert number into column, so when print the table it will be ordered by order column. so far so good Now, I'm trying to make an edit page, so the user can change the order, but my problem is how to handle the form well. my code is working like this

  1. I check how many food in the table
  2. print all food
  3. make an input next to each food

but I got stuck with this problem, I don't know how to write a code to sql UPDATE the table if I don't know how many inputs there are, usually I know how many I. I think it's by using while loop, I didn't figure out, could help please

my codes:

<form action="" method="POST">  while($row = mysqli_fetch_assoc($result)) {              echo '              <tr>                <td>'.$row['seq'].'</td>                <td><input type="text" value="'.$row['seq'].'" name="vertical-spin'.$row['id'].'"></td>                <td class="txt-dark">'.date('d-m-Y', $row['time']).'</td>                <td class="txt-dark">'.$row['title'].'</td>                <td>'; if($row['active']) {echo '<span class="txt-success">show</span>'; } else { echo '<span class="txt-danger">hidden</span>'; } echo '</td>                <td><img src="../food/'.$row['id'].'.jpg" alt="iMac" width="120"></td>              </tr>              ';            }  </form>  

look like this enter image description here

my problem is how to handle the values into sql UPDAUTE since I don't know how many values there are

https://stackoverflow.com/questions/66094614/how-to-make-a-form-if-you-do-not-how-much-inputs-you-have February 08, 2021 at 08:44AM

没有评论:

发表评论