M
M
MisTFoR2021-10-08 18:31:47
PHP
MisTFoR, 2021-10-08 18:31:47

Why doesn't the cycle stop?

Hello!
I have a database with 2 tables (epg and channel), they have 2 identical columns - id_channel.
For a test, I'm trying to connect 2 tables (to use records) and output them.

$result = mysql_query("SELECT `epg`.id_channel AS id_channel_epg, `channel`.id_channel AS id_channel_channel FROM `epg`, `channel`", $link);
while($row = mysql_fetch_array($result)){
    echo $row['id_channel'];
}

Data is output - but endlessly, it is generated and generated. Though if I am connected to one table - that everything is normal.
What to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2021-10-08
@Rsa97

I highly doubt it will be infinite. You have written a complete Cartesian product of tables. So the number of rows in the output will be equal to the product of the number of rows in the first table by the number of rows in the second table.

T
ThunderCat, 2021-10-08
@ThunderCat

it looks like you need to join tables by foreign key .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question