Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
Selecting the latest entry in a single MYSQL column and assigning it to a php variable

I have a 4 column mysql table, the leftmost being the autoincrement column and I'd like to get the variable value for a column called extra for the highest auto increment value. I believe the SQL query will be:

Select extra FROM motoron2 ORDER BY id DESC LIMIT 1"

    $conn = new mysqli('localhost', 'myuser', 'mypass', 'mydb');    
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }
    $sql = "SELECT extra FROM motoron2 ORDER BY id DESC LIMIT 1";
    $stmt = $conn->prepare($sql); 
    $stmt->execute();
    $result = $stmt->get_result(); // get the mysqli result
    $variablevalue = $result->fetch_assoc(); // fetch the data 
    echo "The variable is converted to a string and its value is $variablevalue.";
    // set parameters and execute

When try to echo "The variable is converted to a string and its value is $variablevalue." I see: The variable is converted to a string and its value is Array I am expecting to see an integer here, what am I doing wrong?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The fetch_assoc() function returns an associative array so you would access the value by the name of the column:

$variablevalue['extra'];

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda