pa*****************@hotmail.com says...
Hi,
I am trying to execute 2 queries and then output the results in 2 loops but
maybe I'm using the wrong approach.
Can anyone help me here ...
$query_1 = "SELECT field_1 FROM table_1";
$result_1 = mysql_query($query_1) or die(mysql_error());
$query_2 = "SELECT field_2 FROM table_2";
$result_2 = mysql_query($query_2) or die(mysql_error());
while ($row_1 = mysql_fetch_row($result_1))
{
while ($row_2 = mysql_fetch_row($result_2))
{
print $row_1[0] . ' - ' . $row_2[0] . '<BR>';
}
}
What exactly are you trying to do?
Print a complete list of the values in $query_2 for each and every value
in $query_1? If so, why not just do a single query with a Cartesian (no
join) state:
$query = "SELECT field_1, field_2 FROM table_1, table_2";
Alternatively, you can get that result by:
$query_1 = "SELECT field_1 FROM table_1";
$query_2 = "SELECT field_2 FROM table_2";
$result_1 = mysql_query($query_1) or die(mysql_error());
while ($row_1 = mysql_fetch_row($result_1))
{
$result_2 = mysql_query($query_2) or die(mysql_error());
while ($row_2 = mysql_fetch_row($result_2))
{
print $row_1[0] . ' - ' . $row_2[0] . '<BR>';
}
}
But why are you looping through two tables that appear to have no
relationship?
Geoff M