I have 2 requests on a SQL database. It takes really long to load the whole script / page. Is there a better (faster) way? My code looks like this
$abfrage = "SELECT * FROM table_a WHERE state = '0' ORDER BY EDIT DESC";
$stmt = $pdo->query($abfrage);
foreach($stmt as $data) { ?>
$usern = $data['user_name'];
$stmt = $pdo->query("SELECT * FROM tabl_b WHERE user_name = '$usern' ORDER BY follower DESC Limit 1");
$stmt->execute();
$pl = $stmt->fetch();
<?php echo $data['ID'];?>
<?php echo $data['ID'];?>
<?php if ($data['company'] == '') { ?>
<a href="https://open.spotify.com/user/<?php echo $data['user_name'];?>" target="_blank"><?php if ($data['state'] == '3') { echo "<span style=\"color:#0000FF\";>".$data['user_name']."</span>"; } else { echo $data['user_name'];}?></a>
<?php } else {?>
<a href="https://open.spotify.com/user/<?php echo $data['user_name'];?>" target="_blank"><?php if ($data['state'] == '3') { echo "<span style=\"color:#0000FF\";>".$data['company']."</span>"; } else { echo $data['company'];}?></a>
<?php } ?>
<?php echo $data['PL_read'];?>
<?php echo $data['PL_total'];?>
<?php echo $data['country'];?>
<?php echo $data['EDIT'];?>
<?php echo $pl['follower'];?>
<?php } ?>
I have a table around th echo data. I would be great if someone can give me a tip.