I have this section of cod:
how i can stop this section
for($i=0; $i<$n-1 ; $i++) {
mysqli_query($con,"INSERT INTO text (ID, TXT)
VALUES ('$id', '$sir[$i]')");
$id++;
}
if table isn't empty ?
You need to add before the specific block:
// count the rows
$res = mysqli_query($con, "SELECT COUNT(ID) as numrows FROM text");
// fetch the result
$data=mysql_fetch_assoc($res);
// check if count = 0
if($data['numrows'] == 0) {
// execute the codeblock
for($i=0; $i<$n-1 ; $i++) {
mysqli_query($con,"INSERT INTO text (ID, TXT)
VALUES ('$id', '$sir[$i]')");
$id++;
}
}
Just a select a row and see what happens...
if (!($result = mysqli_query($con, "SELECT ID FROM text LIMIT 1")) || $result->num_rows < 1) {
if($result) {
$result->close();
}
for ($i = 0; $i < $n - 1; $i++) {
mysqli_query($con, "INSERT INTO text (ID, TXT)
VALUES ('$id', '$sir[$i]')");
$id++;
}
}