I'm trying to create a query that will pull data from one table, and display it using a while() loop. In the while loop I've setup a second query to be run, but things aren't working out like I thought they would.
Here's an example of the code.
$sql1 = "SELECT $table1";
$sql2 = "SELECT $table2";
$res1 = mysql_query($sql1);
$res2 = mysql_query($sql2);
while ( $row = mysql_fetch_array($res1)){
$column = $row['column'];
echo("$column");
while ( $row_2 = mysql_fetch_array($res2)){
$column_2 = $row_2['column_2'];
echo(" $column");
}
}
What I thought would happen was I get a result like this:
$column
$column_2
$column
$column_2
$column
$column_2
Instead what I get is:
$column
$column_2
$column_2
$column_2
$column
$column
All of the results end up under the first value returned from the first query. Am I using the wrong mysql function, or do I not have my while loops set up correctly?