I have an error in executing a while loop in php. actually in php code I tried to fetch records from database for that i establish connection at the beginning of code.In code my outer loop executed well but inner loop executed only one time and terminated.Then i tried to establish mysql connection once again within while loop then it executed.If i comment this it not work well.Tell me to run while loop there is need to establish connection once again or there is another way to solve problem.
Here is my code:
$con = mysqli_connect("localhost", "root", "root", "scheduler");
$sql = "select * from jobschedule";
$result = mysqli_query($con,$sql);
$sql2 = "SET GLOBAL event_scheduler = 1";
mysqli_query($con,$sql2);
while($row = mysqli_fetch_array($result))
{
// $con = mysqli_connect("localhost", "root", "root", "scheduler");
$dbname = $row['DBName'];
$jobname = $row['JobName'];
$sql1 = "call $dbname.$jobname";
$result1 = mysqli_query($con,$sql1);
while($row1 = mysqli_fetch_array($result1))
{
echo '<tr>';
. '<td>' . $row1['Name'] . '</td>';
. '<td>' . $row1['CountryCode'] . '</td>'
. '<td>' . $row1['District'] . '</td>'
. '<td>' . $row1['Population'] . '</td>'
. '</tr>';
}
}