vendredi 17 janvier 2020

Please Help : Create auto code sequential PHP

I have data

A1

A2

A4

A5

when I enter new data, I want "A3" and the next new data "A6", so I want new data to fill in the blank data first.

I've tried with this code:

$sql = "SELECT max(idalternatif) as maxcode from alternatif";
                    $result = mysqli_query($connect,$sql);
                    $data = mysqli_fetch_array($result);
                    $idalternatif = $data['maxcode'];

                    $no = (int) substr($idalternatif,1,1);
                    for($x=1; $x<=$no; $x++){
                    if ($x == 0){
                        $char = "A";
                    $id = $char . $x;
                    }
                    else{
                    $char = "A";
                    $id = $char . $x++;
                    }
                    }

Its still give me an error result. Please help me

Aucun commentaire:

Enregistrer un commentaire