I'm trying to do a loop in php where i have a variable "i" what's value is "1" and if in my database the value of my variable exist it will execute a script and add 1 to my variable and etc. to the time that the value of my variable does not exist in my database. There is my code :
config.php :
<?php
/* Database connection */
$sDbHost = 'localhost';
$sDbName = 'techtronik.pl';
$sDbUser = 'root';
$sDbPwd = '';
$dbcon = mysqli_connect ($sDbHost, $sDbUser, $sDbPwd, $sDbName);
?>
anotherfile.php :
<?php
include('config.php');
$sqlget = "SELECT * FROM pcstacjonarne";
$sqldata = mysqli_query($dbcon, $sqlget)or die("Nie udalo sie polaczyc z baza danych");
$row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC);
$i = 4;
$result = $dbcon->query("SELECT * FROM pcstacjonarne WHERE idpcstacjonarne = '$i'");
while ($result->num_rows == 1) {
echo 'Number of post is '.($i++);
}
?>
But this code don't work i am trying to fix this for 3 hours but i really don't now where is the problem. If someone would help me it will be great.
$result->num_rowsis 1 then it will always remain 1.$result->num_rowswill never change). If you have more than 1 result, the while loop will never iterate at all.SELECT MAX(idpcstacjonarne) FROM pcstacjonarne$row) for?