I generate the png img by calling the other php file.
The first is :
echo '<table>';
$a = 1;
while ($a <=2) {
session_start();
$_SESSION['a'] = $a;
echo '<td>';
echo '<img src="http://localserver/pic.php"/>';
echo '</td>';
a++;
}
echo '</table>;
The pic.php
session_start();
$b = $_SESSION['a'];
if($a == $b) {
Qrcode::png($link,false,"L",2,2);
}
Suppose when a = 1 , The would be an qrcode generated and shown on table row 1 and when a=2 , no qr will be generated, the above lines of pic.php will skip.
I can generate properly when I run it seperately( if $a == 1) , if($a ==2).
However when I do the while loop , looping $b= 1 then $b=2 The qrcode of the row 1(case if $a==1) disappeared.
Why this happened?
You have syntax error in this line. $
missing in variable name.
a++;
It will be
$a++;
Also in
echo '</table>;
Will be
echo '</table>';
Your while loop will also be performed for $a=2
as you have used less than or equal
condition. To perform only for $a = 1
change condition to
while ($a <=1)
Also session_start() should be at top of the file.
session_start(); // move this
echo '<table>';
$a = 1;
while ($a <=2) {
$_SESSION['a'] = $a;
echo '<td>';
echo '<img src="http://localserver/pic.php"/>';
echo '</td>';
$a++;
}
echo '</table>';
And
session_start(); // add this
$b = $_SESSION['a'];
if($a == $b) {
Qrcode::png($link,false,"L",2,2);
}
your a++ at line 10 doesn't have $ symbol, hence its not taking it as variable. Make the code as below
session_start(); // you need to run session start only once, not required to run it in loop
echo '<table>';
$a = 1;
while ($a <=2) {
$_SESSION['a'] = $a;
echo '<td>';
echo '<img src="http://localserver/pic.php"/>';
echo '</td>';
$a++;
}
echo '</table>';