php pdo get only one value from mysql; value that equals to variable

You have to use the fetch function according to your desired result.

  1. If you need a single scalar value, no column name is ever needed:

     $Number1 = $stmt->fetchColumn();
    
  2. If there are many results to be returned, but only one column per row, no need for the column name again:

     $numbers = $sth->fetchAll(PDO::FETCH_COLUMN);
    

    It will return an array of numbers.

  3. If you need a single row with multiple values, then use fetch()

  4. If you need array of rows, use fetchAll()


first change

$Number1 = $stmt->fetchAll(PDO::FETCH_ASSOC);

to

$Number1 = $stmt->fetch(PDO::FETCH_ASSOC);

since I believe you are retrieving only 1 row..

you will get ur number as

echo $Number1['Number']

Dins

Tags:

Mysql

Php

Pdo