Ok i have a lot of tables that are created when a user inputs information. Some info gets stored in a "Main" table while the majority is saved in its own self created table. I do not know the number of "topics" in Main table. so in way i'm trying to make a double query but i'm not sure if i'm saving the $all variable correctly.

$sql= "select * from main";
$all= while($row=mysql_fetch_array($result)){;
$all.=     echo ”Select * From ". ($row[‘topic’]);
$all.= if($i <$counter){;
$all.=                echo “ UNION ALL “;
$all.= }else{;
$all.=                Echo “ ORDER BY id DESC ”;
$all.= }};

    echo  $row[‘name’] $row[‘age’] $row[‘city’] $row[‘state’] ;

I keep getting Unexpected T_While and Unexpected T_Variables in the lines where the while starts and where $row is used. I've done research and tutorials say that those errors are usually due to a missing ; but i dunno i'm stuck... Any suggestions on my $all variable?

Your syntax is way off:

$sql = 'select * from main';
$result = mysql_query($sql);
$counter = mysql_num_rows($sql);

$i = 1;
while ($row = mysql_fetch_array($result))
  $all .= 'Select * From ' . $row['topic'];
  if ($i < $counter)
    $all .= ' UNION ALL ';
    $all .= ' ORDER BY id DESC ';
$query = mysql_query($all);
while ($row = mysql_fetch_array($query))
  echo $row['name'] . $row['age'] . $row['city'] . $row['state'];
This article has been dead for over six months. Start a new discussion instead.