Insert data into the database, Insert into the desired cell (a loop or something)?

there is a table with entries of the format:

id | A | b | c | D|

so you need to insert, let’s say some id in a cycle, into the cell that is not occupied!
those. valid if there is data:

0 | 12 | 32 | 43 | 14 |
1 | 54 | 55 |___|___|

then insert id into the next. an empty cell, in this example it is the cell that comes after 55, if all the cells are filled, then you need to make a new entry and insert the id into the 1st cell of the new entry. I hope I explained clearly.


Answer 1, authority 100%

$q="SELECT * FROM `table` ORDER BY id DESC LIMIT 0,1";
$d=mysql_fetch_array(mysql_query($q),MYSQL_ASSOC);
if(is_array($d)){
  $id=$d["id"];
  foreach($d as $k=>$v){
    if(!$v){
        if(length($q1))$q1.=", ";
        $q1.=$k."='".  ."'";
    }
  } 
  $q1="UPDATE `table` SET ".$q1." WHERE id=".$id;
  mysql_query($q1);
}

Thus, we filled in the empty fields of incomplete lines, provided that the field id = auto_increment

Next, just make direct requests.

Leave a reply

Please enter your comment!
Please enter your name here