How to return the average of one field of a recordset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kelly Butler

    #1

    How to return the average of one field of a recordset

    I have a php file which allows users to select up to 11 different selects to narrow down which parts/products best meet their requirements.

    The php returns a table listing all products which meet their requirements as indicated by the selects that they have chosen.

    I have a 12th field that is not shown in the table. That field as "photo values". The average of the "photo values" determines which photo is shown along with the table.

    The code for my select is:

    Code:
    mysql_select_db($database_swagesert, $swagesert);
    $query_rsswagesert = sprintf("SELECT PartNo, IntThd, ExtThd, Lgth, MSNumber, Matl, DecID, DecOD, Pitch, Lok, Finish, Photo FROM swagesert WHERE PartNo LIKE %s AND short LIKE %s AND IntThd LIKE %s AND ExtThd LIKE %s AND Lgth LIKE %s AND Matl LIKE %s AND DecID LIKE %s AND DecOD LIKE %s AND Pitch LIKE %s AND Lok LIKE %s AND Finish LIKE %s" , 
    GetSQLValueString($colname1_rsswagesert, "text"),
    GetSQLValueString($colname2_rsswagesert, "text"),
    GetSQLValueString($colname3_rsswagesert, "text"),
    GetSQLValueString($colname4_rsswagesert, "text"),
    GetSQLValueString($colname5_rsswagesert, "text"),
    GetSQLValueString($colname6_rsswagesert, "text"),
    GetSQLValueString($colname7_rsswagesert, "text"),
    GetSQLValueString($colname8_rsswagesert, "text"),
    GetSQLValueString($colname9_rsswagesert, "text"),
    GetSQLValueString($colname10_rsswagesert, "text"),
    GetSQLValueString($colname11_rsswagesert, "text"),
    GetSQLValueString($colname12_rsswagesert, "text"));
    $rsswagesert = mysql_query($query_rsswagesert, $swagesert) or die(mysql_error());
    $row_rsswagesert = mysql_fetch_assoc($rsswagesert);
    $totalRows_rsswagesert = mysql_num_rows($rsswagesert);
    And the select gets called with:

    Code:
    <?php 
    do { ?>
    <tr class="chart">
    <td><?php echo $row_rsswagesert['PartNo']; ?></td>
    <td><?php echo $row_rsswagesert['MSNumber']; ?></td>
    <td><?php echo $row_rsswagesert['IntThd']; ?></td>
    <td><?php echo $row_rsswagesert['ExtThd']; ?></td>
    <td><?php echo $row_rsswagesert['Lgth']; ?></td>
    <td><?php echo $row_rsswagesert['Matl']; ?></td>
    <td><?php echo $row_rsswagesert['DecID']; ?></td>
    <td><?php echo $row_rsswagesert['DecOD']; ?></td>
    <td><?php echo $row_rsswagesert['Pitch']; ?></td>
    <td><?php echo $row_rsswagesert['Lok']; ?></td>
    <td><?php echo $row_rsswagesert['Finish']; ?></td>
    </tr> 
    <?php
    	   } while ($row_rsswagesert = mysql_fetch_array($rsswagesert)); ?>
    </table>
    How can I get the average of the 'Photo' field to return so the photovalue can be determined?
Working...