DroiDar DroiDar - 1 year ago 68
SQL Question

PHP Prepared Statements: Echo the Result

i want to Display the Result ('Positio: 2' or 'Position: 1') via a Echo
but $statement is a Object of class PDOStatement and not a String, how do i get it to see only the result of $statement? Thank you

$pdo = new PDO('mysql:host=localhost;dbname=testdb1', 'root', '');

$idV = $_GET['id'];

$statement = $pdo->prepare("SELECT position FROM idtabelle WHERE idnumber = ?");

echo "Position: //$result_Of_Statement\\ ";

Answer Source

Here's how I would do it:

$statement = $pdo->prepare("SELECT position FROM idtabelle WHERE idnumber = :idV");
$statement->bindParam(':idV', $idV);
while ($row = $statement->fetch(PDO::FETCH_ASSOC))
  echo $row['position'];

You could also do away with the while loop if you wanted to.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download