How can I pass PHP GET URL variables to open a window with Javascript?
Don't forget to quote the url in the Javascript open
function. Also, did you consider using printf()
for outputting?
$link =
'<a href="" onclick="window.open(\'profile.php?id=%d\')">'
. '<img src="../%s" width="100" height="100" /></a>' . PHP_EOL;
for($i = 1; $i <= $row_count; $i++) {
$row = $result->fetch_assoc();
printf($link,$row['ID'],$row['Picture']);
}
%d
represents a decimal and %s
represents a string in the above string (hence the $link
). Another tip: if you have no particular reason to use the for loop, using a while loop instead will make your code cleaner and shorter.
while ($row = $result->fetch_assoc()) {
printf($link,$row['ID'],$row['Picture']);
}