php - using for loop on mysql table
905
I have 2 tables on my db: cat (id, catname) link (id, name, url, cat)
I wanted to loop through the tablelink
and output data bycat
, here the actual code but id doesn't work anyway :)
for ($i = 1; ; $i++)
{
$list = $mysqli->query('SELECT * FROM links WHERE category='$i'');
while($row = $list->fetch_assoc()) {
print $row["category"];
print $row["name"].' ';
print $row["url"];
print '<br>';
}
}
$list->free();
Is there a way we can get theid
from tablecat
and use that to loop through the data in tablelink
?
Thanks
Answer
Solution:
No need for so many requests inside the loop. There are JOIN statements in SQL for such cases: