<?php
include("config/config.php");

// Consulta SQL para contar la cantidad de autores no vacíos en los campos autor1 a autor10
$query = "
    SELECT 
        SUM(CASE WHEN autor1 IS NOT NULL AND autor1 != '' THEN 1 ELSE 0 END) +
        SUM(CASE WHEN autor2 IS NOT NULL AND autor2 != '' THEN 1 ELSE 0 END) +
        SUM(CASE WHEN autor3 IS NOT NULL AND autor3 != '' THEN 1 ELSE 0 END) +
        SUM(CASE WHEN autor4 IS NOT NULL AND autor4 != '' THEN 1 ELSE 0 END) +
        SUM(CASE WHEN autor5 IS NOT NULL AND autor5 != '' THEN 1 ELSE 0 END) +
        SUM(CASE WHEN autor6 IS NOT NULL AND autor6 != '' THEN 1 ELSE 0 END) +
        SUM(CASE WHEN autor7 IS NOT NULL AND autor7 != '' THEN 1 ELSE 0 END) +
        SUM(CASE WHEN autor8 IS NOT NULL AND autor8 != '' THEN 1 ELSE 0 END) +
        SUM(CASE WHEN autor9 IS NOT NULL AND autor9 != '' THEN 1 ELSE 0 END) +
        SUM(CASE WHEN autor10 IS NOT NULL AND autor10 != '' THEN 1 ELSE 0 END) AS total_autores
    FROM ttrabajo
";

$result = $conexion->query($query);

if (!$result) {
    die("Error en la consulta: " . $conexion->error);
}

$row = $result->fetch_assoc();
$total_autores = $row['total_autores'];

$conexion->close();
?>

<!-- Mostrar el total de autores en tu página -->
<div>
    <?php echo $total_autores; ?>
</div>
