I have a table with: name1, name2, hours1, hours2. A person can be in either name1 or name2 column and I am trying to total their hours and it does not matter if they are list in name1 or name2. I get their names but “0” for the totals. What am I doing wrong in the sumhours?
[code=php]$query=”
SELECT DISTINCT name1 AS name FROM lss
UNION
SELECT DISTINCT name2 AS name FROM lss WHERE name2!=”
UNION
SELECT SUM(hours1) AS sumhours1 FROM lss
UNION
SELECT SUM(hours2) AS sumhours2 FROM lss”;
$result = mysql_query($query) or die(“Couldn’t execute query: “.mysql_error());
while ($rows=mysql_fetch_array($result)) {
$name=$rows[‘name’];
$sumhours1=$rows[‘sumhours1’];
$sumhours2=$rows[‘sumhours2’];
$hours=($sumhours1+$sumhours2);
echo “<tr><td>$name</td>”;
echo “<td>$hours</td>”;
}