Substr() does not work

Asked

Viewed 88 times

-2

I cannot understand why the substr is not working. Follow the code:

<?php

    // conexão com bd

    $host = "localhost";
    $user = "root";
    $pass = "";
    $db = "loja";

    $conexao = mysqli_connect($host, $user, $pass, $db);

    $consulta = "Select concact(substr(nome,1,10),'...') as nome from produtos";
    $resultado = mysqli_query($conexao, $consulta);

    while($linha = mysqli_fetch_array($resultado)){

    ?>

    <p> <?php echo $linha['nome']; ?> </p>

    <?php


    }
?>
  • Which is the expected output and which was the obtained output? What are the records present in the database?

  • I expected to leave, for example, the name of the product followed by ellipsis after the tenth character (ex: Phi LCD TV...) but points out the following error: Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs December test.php on line 15

  • Your select is wrong. Try running it straight in mysql to see the full message, but probably concact should be Concat

  • 1

    Please do not omit information the next time you ask. If you have made a mistake, put at all times the error message.

  • Gee, I didn’t even notice the mistake. Thank you very much!

2 answers

1

The error is in the "concact" command, where the correct is "Concat".

1

The function CONCAT in your query is misspelled, change it which will work:

 $consulta = "SELECT CONCAT(SUBSTR(nome,1,10),'...') AS nome FROM produtos";

Browser other questions tagged

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