Query return , Fatal error: Maximum Execution [PHP]

Asked

Viewed 45 times

1

            <tr>
              <td id="titulo">
                <a href="./visualizar" data-html="true"
                            data-trigger="hover" data-container="body" data-toggle="popover" data-placement="right" data-content="<?= $p[$i]->titulo; ?>">
                  <?php
                    $str = $p[$i]->titulo;
                    echo text_limiter_caracter($str, 32, '...');
                  ?>
                </a>
              </td>
              <td id="edital">
                <span data-html="true" data-trigger="hover" data-container="body" data-toggle="popover" data-placement="right" data-content="<?= $p[$i]->edital; ?>" >
                  <?php
                    $stred = $p[$i]->edital;
                    echo text_limiter_caracter($stred, 32, '...');
                  ?>
                </span>
              </td>
            </tr>

function text_limiter_caracter($str, $limit, $suffix = '...')
{
    while (substr($str, $limit, 1) != ' ') {
        $limit--;
    }

    if (strlen($str) <= $limit) {
        return $str;
    }

    return substr($str, 0, $limit + 1) . $suffix;

}

The system is returning me an unwanted loop , what I want and return a string equal to the title.

Nao sei o que esta de errado :/

Model public Function listarProjetoPage($location, $start, $max) {

    $sql  = "SELECT t1.titulo,t3.nome as edital, t2.nome as area
             FROM projeto t1
             INNER JOIN areaconhecimento t2 on (t2.id = t1.idAreaConhecimento)
             INNER JOIN edital t3 on (t3.id = t1. ) WHERE t1.situacao = $situacao ORDER BY t1.titulo LIMIT $inicio, $max";

    $stmt = $this->conn->prepare($sql);
    $stmt->execute();

    return $stmt->fetchAll();

}

Controller

function listarProjetoPage($situacao, $inicio, $max) {

    $resultado = $this->projetos->listarProjetoPage($situacao, $inicio, $max);
    return $resultado;
}
  • What do you want to achieve with this loop ?

  • I wish to return a shortened word as in the title...

  • Because this code is not known what is causing the error, basically it says, the work that php should do in up to 30 seconds took longer than that. Is it a consultation? post her.

  • The line 143 is echo text_limiter_caracter($stred, 32, '...'); ?

  • Error solved .

  • To shorten a word/phrase you need a loop to ?

Show 1 more comment

1 answer

1


    function text_limiter_caracter($str, $limit, $suffix = '...')
    {
      if (strlen($str) <= $limit) {
        return $str;
      }else{
        return substr($str, 0, $limit + 1) . $suffix;
      }
    }

The Error was in the while, because it was checking for " (space), and in my first notice there was no space so it generated a loop in the while.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.