-3

Hi anyone know how to get the TID. I only need the TID and set it to variable $TID

$sql = 'SELECT TID FROM  walkin ORDER BY TID DESC LIMIT 1';

$result = mysqli_query($conn, $sql);

if ($conn->error) {
    die("Query failed: " . $conn->error);
}
$TID = /answer here/
Kevin
  • 41,694
  • 12
  • 53
  • 70
  • Possible duplicate of [mysql query result in php variable](https://stackoverflow.com/questions/5157905/mysql-query-result-in-php-variable) – Kasnady Feb 23 '18 at 01:45
  • 1
    Have you checked the [**documentation**](http://php.net/manual/en/class.mysqli-result.php)? And have you tried anything so far? StackOverflow isn't a free code-writing service, and expects you to [**try to solve your own problem first**](http://meta.stackoverflow.com/questions/261592). Please update your question to show what you have already tried, showcasing a **specific** problem you are facing in a [**minimal, complete, and verifiable example**](http://stackoverflow.com/help/mcve). – Obsidian Age Feb 23 '18 at 01:46
  • 1
    Maybe `fetch` it. Wherever you saw `query` and `error` they didn't show an example of fetching? – AbraCadaver Feb 23 '18 at 01:56

1 Answers1

0

How about a prepared statement with a bind_result and fetch call?

if($stmt=$conn->prepare("SELECT TID FROM walkin ORDER BY TID DESC LIMIT 1")){
    if($stmt->execute() && $stmt->bind_result($TID) && $stmt->fetch()){
        echo $TID;
    }
}
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
  • @Isaiah Did my answer solve your problem? If so, please award the green tick to my answer. If not, please leave me a comment describing what has gone wrong for you while implementing. – mickmackusa Feb 24 '18 at 08:29