PHP/MYSql PDO Select with variable





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















Edit: Ok, so while this does work great for $ID when I set it equal to 28, it is not working for instance below if I was trying to get the $name = $TableRows['name']; variable. I know I could select it, but other variables require this.



$ID = 28; 
$name = $TableRows['name'];

try { ini_set('display_errors', true);
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare(" SELECT ? AS name FROM TABLE1 e WHERE id = ?");
$stmt->execute(array($name, $ID));
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}


I'm in the process of transitioning from MySQLi to PDO. My problem is I'd like to modify one of the values in my SELECT query, similar to how I set my WHERE value of ID to $ID = 28. Does anyone know how instead of just outputting millisecondstime from the SELECT query, I could change it to output $minutes $secondsrounded $millisecondsround instead? This is the idea that I am going for:



$stmt = $conn->prepare("SELECT name, $minutes, $secondsrounded, $millisecondsround FROM TABLE1 e


This is my entire query:



<?php
echo "<center><div style='max-width: 1100px'><table id ='myTable' class='display' cellspacing='0' width='100%'>
<thead>
";
echo "<tr><th>Name</th><th>Time</th></tr></thead>";

class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}

function current() {
return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>";
}

function beginChildren() {
echo "<tr>";
}

function endChildren() {
echo "</tr>" . "n";
}
}

$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

$name = $TableRows['name'];

$milliseconds = $TableRows['millisecondstime'];

$time = $milliseconds / 1000;
$days = floor($time / (24*60*60));
$hours = floor(($time - ($days*24*60*60)) / (60*60));
$minutes = floor(($time - ($days*24*60*60)-($hours*60*60)) / 60);
$seconds = ($time - ($days*24*60*60) - ($hours*60*60) - ($minutes*60)) % 60;

$str_length = 3;
$millisecondsround = substr("000{$milliseconds}", -$str_length);
$secondsrounded = str_pad($seconds, 2, '0', STR_PAD_LEFT);

$ID = 28;

try {
ini_set('display_errors', true);
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $conn->prepare("SELECT name, millisecondstime FROM TABLE1 e
WHERE ID = ?
ORDER BY millisecondstime ASC
");

$stmt->execute(array($ID));
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>









share|improve this question




















  • 1





    That isn't a very good db design having minutes, seconds and miliiseconds as column names. Why would you want to do that?

    – Funk Forty Niner
    Nov 15 '18 at 23:03













  • They're not the column names. They are the variables I'm setting and manipulating from the millisecondstime value.

    – duke
    Nov 15 '18 at 23:09











  • Ok. Well Barmar seems to have a solution for you; give that a whirl.

    – Funk Forty Niner
    Nov 15 '18 at 23:10


















1















Edit: Ok, so while this does work great for $ID when I set it equal to 28, it is not working for instance below if I was trying to get the $name = $TableRows['name']; variable. I know I could select it, but other variables require this.



$ID = 28; 
$name = $TableRows['name'];

try { ini_set('display_errors', true);
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare(" SELECT ? AS name FROM TABLE1 e WHERE id = ?");
$stmt->execute(array($name, $ID));
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}


I'm in the process of transitioning from MySQLi to PDO. My problem is I'd like to modify one of the values in my SELECT query, similar to how I set my WHERE value of ID to $ID = 28. Does anyone know how instead of just outputting millisecondstime from the SELECT query, I could change it to output $minutes $secondsrounded $millisecondsround instead? This is the idea that I am going for:



$stmt = $conn->prepare("SELECT name, $minutes, $secondsrounded, $millisecondsround FROM TABLE1 e


This is my entire query:



<?php
echo "<center><div style='max-width: 1100px'><table id ='myTable' class='display' cellspacing='0' width='100%'>
<thead>
";
echo "<tr><th>Name</th><th>Time</th></tr></thead>";

class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}

function current() {
return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>";
}

function beginChildren() {
echo "<tr>";
}

function endChildren() {
echo "</tr>" . "n";
}
}

$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

$name = $TableRows['name'];

$milliseconds = $TableRows['millisecondstime'];

$time = $milliseconds / 1000;
$days = floor($time / (24*60*60));
$hours = floor(($time - ($days*24*60*60)) / (60*60));
$minutes = floor(($time - ($days*24*60*60)-($hours*60*60)) / 60);
$seconds = ($time - ($days*24*60*60) - ($hours*60*60) - ($minutes*60)) % 60;

$str_length = 3;
$millisecondsround = substr("000{$milliseconds}", -$str_length);
$secondsrounded = str_pad($seconds, 2, '0', STR_PAD_LEFT);

$ID = 28;

try {
ini_set('display_errors', true);
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $conn->prepare("SELECT name, millisecondstime FROM TABLE1 e
WHERE ID = ?
ORDER BY millisecondstime ASC
");

$stmt->execute(array($ID));
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>









share|improve this question




















  • 1





    That isn't a very good db design having minutes, seconds and miliiseconds as column names. Why would you want to do that?

    – Funk Forty Niner
    Nov 15 '18 at 23:03













  • They're not the column names. They are the variables I'm setting and manipulating from the millisecondstime value.

    – duke
    Nov 15 '18 at 23:09











  • Ok. Well Barmar seems to have a solution for you; give that a whirl.

    – Funk Forty Niner
    Nov 15 '18 at 23:10














1












1








1


1






Edit: Ok, so while this does work great for $ID when I set it equal to 28, it is not working for instance below if I was trying to get the $name = $TableRows['name']; variable. I know I could select it, but other variables require this.



$ID = 28; 
$name = $TableRows['name'];

try { ini_set('display_errors', true);
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare(" SELECT ? AS name FROM TABLE1 e WHERE id = ?");
$stmt->execute(array($name, $ID));
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}


I'm in the process of transitioning from MySQLi to PDO. My problem is I'd like to modify one of the values in my SELECT query, similar to how I set my WHERE value of ID to $ID = 28. Does anyone know how instead of just outputting millisecondstime from the SELECT query, I could change it to output $minutes $secondsrounded $millisecondsround instead? This is the idea that I am going for:



$stmt = $conn->prepare("SELECT name, $minutes, $secondsrounded, $millisecondsround FROM TABLE1 e


This is my entire query:



<?php
echo "<center><div style='max-width: 1100px'><table id ='myTable' class='display' cellspacing='0' width='100%'>
<thead>
";
echo "<tr><th>Name</th><th>Time</th></tr></thead>";

class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}

function current() {
return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>";
}

function beginChildren() {
echo "<tr>";
}

function endChildren() {
echo "</tr>" . "n";
}
}

$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

$name = $TableRows['name'];

$milliseconds = $TableRows['millisecondstime'];

$time = $milliseconds / 1000;
$days = floor($time / (24*60*60));
$hours = floor(($time - ($days*24*60*60)) / (60*60));
$minutes = floor(($time - ($days*24*60*60)-($hours*60*60)) / 60);
$seconds = ($time - ($days*24*60*60) - ($hours*60*60) - ($minutes*60)) % 60;

$str_length = 3;
$millisecondsround = substr("000{$milliseconds}", -$str_length);
$secondsrounded = str_pad($seconds, 2, '0', STR_PAD_LEFT);

$ID = 28;

try {
ini_set('display_errors', true);
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $conn->prepare("SELECT name, millisecondstime FROM TABLE1 e
WHERE ID = ?
ORDER BY millisecondstime ASC
");

$stmt->execute(array($ID));
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>









share|improve this question
















Edit: Ok, so while this does work great for $ID when I set it equal to 28, it is not working for instance below if I was trying to get the $name = $TableRows['name']; variable. I know I could select it, but other variables require this.



$ID = 28; 
$name = $TableRows['name'];

try { ini_set('display_errors', true);
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare(" SELECT ? AS name FROM TABLE1 e WHERE id = ?");
$stmt->execute(array($name, $ID));
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}


I'm in the process of transitioning from MySQLi to PDO. My problem is I'd like to modify one of the values in my SELECT query, similar to how I set my WHERE value of ID to $ID = 28. Does anyone know how instead of just outputting millisecondstime from the SELECT query, I could change it to output $minutes $secondsrounded $millisecondsround instead? This is the idea that I am going for:



$stmt = $conn->prepare("SELECT name, $minutes, $secondsrounded, $millisecondsround FROM TABLE1 e


This is my entire query:



<?php
echo "<center><div style='max-width: 1100px'><table id ='myTable' class='display' cellspacing='0' width='100%'>
<thead>
";
echo "<tr><th>Name</th><th>Time</th></tr></thead>";

class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}

function current() {
return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>";
}

function beginChildren() {
echo "<tr>";
}

function endChildren() {
echo "</tr>" . "n";
}
}

$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

$name = $TableRows['name'];

$milliseconds = $TableRows['millisecondstime'];

$time = $milliseconds / 1000;
$days = floor($time / (24*60*60));
$hours = floor(($time - ($days*24*60*60)) / (60*60));
$minutes = floor(($time - ($days*24*60*60)-($hours*60*60)) / 60);
$seconds = ($time - ($days*24*60*60) - ($hours*60*60) - ($minutes*60)) % 60;

$str_length = 3;
$millisecondsround = substr("000{$milliseconds}", -$str_length);
$secondsrounded = str_pad($seconds, 2, '0', STR_PAD_LEFT);

$ID = 28;

try {
ini_set('display_errors', true);
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $conn->prepare("SELECT name, millisecondstime FROM TABLE1 e
WHERE ID = ?
ORDER BY millisecondstime ASC
");

$stmt->execute(array($ID));
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>






php mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 14:38









Barmar

436k36260365




436k36260365










asked Nov 15 '18 at 22:37









dukeduke

65




65








  • 1





    That isn't a very good db design having minutes, seconds and miliiseconds as column names. Why would you want to do that?

    – Funk Forty Niner
    Nov 15 '18 at 23:03













  • They're not the column names. They are the variables I'm setting and manipulating from the millisecondstime value.

    – duke
    Nov 15 '18 at 23:09











  • Ok. Well Barmar seems to have a solution for you; give that a whirl.

    – Funk Forty Niner
    Nov 15 '18 at 23:10














  • 1





    That isn't a very good db design having minutes, seconds and miliiseconds as column names. Why would you want to do that?

    – Funk Forty Niner
    Nov 15 '18 at 23:03













  • They're not the column names. They are the variables I'm setting and manipulating from the millisecondstime value.

    – duke
    Nov 15 '18 at 23:09











  • Ok. Well Barmar seems to have a solution for you; give that a whirl.

    – Funk Forty Niner
    Nov 15 '18 at 23:10








1




1





That isn't a very good db design having minutes, seconds and miliiseconds as column names. Why would you want to do that?

– Funk Forty Niner
Nov 15 '18 at 23:03







That isn't a very good db design having minutes, seconds and miliiseconds as column names. Why would you want to do that?

– Funk Forty Niner
Nov 15 '18 at 23:03















They're not the column names. They are the variables I'm setting and manipulating from the millisecondstime value.

– duke
Nov 15 '18 at 23:09





They're not the column names. They are the variables I'm setting and manipulating from the millisecondstime value.

– duke
Nov 15 '18 at 23:09













Ok. Well Barmar seems to have a solution for you; give that a whirl.

– Funk Forty Niner
Nov 15 '18 at 23:10





Ok. Well Barmar seems to have a solution for you; give that a whirl.

– Funk Forty Niner
Nov 15 '18 at 23:10












2 Answers
2






active

oldest

votes


















3














You can use placeholders in the SELECT list, and they'll be replaced with the values from the parameter array.



$stmt = $conn->prepare("
SELECT name, ? AS minutes, ? AS secondsrounded, ? AS millisecondsround
FROM TABLE1 e
WHERE id = ?");
$stmt->execute(array($minutes, $secondsrounded, $millisecondsround, $ID));





share|improve this answer
























  • Can you really do that?

    – Funk Forty Niner
    Nov 15 '18 at 23:05











  • Yes. Placeholders can be used wherever expressions are allowed. You can write SELECT 1 AS minutes FROM ...

    – Barmar
    Nov 15 '18 at 23:07











  • heh, interesting.

    – Funk Forty Niner
    Nov 15 '18 at 23:08











  • I actually have code that does something like this.

    – Barmar
    Nov 15 '18 at 23:08






  • 1





    And while I teach 99% of the time, every now and then I learn something new.

    – Barmar
    Nov 15 '18 at 23:10



















1














Try this instead:



$stmt = $conn->prepare("SELECT name, millisecondstime FROM TABLE1 e
WHERE ID = :ID
ORDER BY millisecondstime ASC
");

$stmt->execute(array('ID' => $ID));





share|improve this answer
























  • It doesn't come from the table, it's a variable he set earlier in the script.

    – Barmar
    Nov 15 '18 at 23:00











  • Thanks, but if I add the other variables to the array, I'll get: Invalid parameter number: number of bound variables does not match number of tokens. I still need to set millisecondstime equal to those three variables. $stmt->execute(array('ID' => $ID, 'millisecondstime' => $minutes $secondsrounded $millisecondsround));

    – duke
    Nov 15 '18 at 23:00














Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328858%2fphp-mysql-pdo-select-with-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














You can use placeholders in the SELECT list, and they'll be replaced with the values from the parameter array.



$stmt = $conn->prepare("
SELECT name, ? AS minutes, ? AS secondsrounded, ? AS millisecondsround
FROM TABLE1 e
WHERE id = ?");
$stmt->execute(array($minutes, $secondsrounded, $millisecondsround, $ID));





share|improve this answer
























  • Can you really do that?

    – Funk Forty Niner
    Nov 15 '18 at 23:05











  • Yes. Placeholders can be used wherever expressions are allowed. You can write SELECT 1 AS minutes FROM ...

    – Barmar
    Nov 15 '18 at 23:07











  • heh, interesting.

    – Funk Forty Niner
    Nov 15 '18 at 23:08











  • I actually have code that does something like this.

    – Barmar
    Nov 15 '18 at 23:08






  • 1





    And while I teach 99% of the time, every now and then I learn something new.

    – Barmar
    Nov 15 '18 at 23:10
















3














You can use placeholders in the SELECT list, and they'll be replaced with the values from the parameter array.



$stmt = $conn->prepare("
SELECT name, ? AS minutes, ? AS secondsrounded, ? AS millisecondsround
FROM TABLE1 e
WHERE id = ?");
$stmt->execute(array($minutes, $secondsrounded, $millisecondsround, $ID));





share|improve this answer
























  • Can you really do that?

    – Funk Forty Niner
    Nov 15 '18 at 23:05











  • Yes. Placeholders can be used wherever expressions are allowed. You can write SELECT 1 AS minutes FROM ...

    – Barmar
    Nov 15 '18 at 23:07











  • heh, interesting.

    – Funk Forty Niner
    Nov 15 '18 at 23:08











  • I actually have code that does something like this.

    – Barmar
    Nov 15 '18 at 23:08






  • 1





    And while I teach 99% of the time, every now and then I learn something new.

    – Barmar
    Nov 15 '18 at 23:10














3












3








3







You can use placeholders in the SELECT list, and they'll be replaced with the values from the parameter array.



$stmt = $conn->prepare("
SELECT name, ? AS minutes, ? AS secondsrounded, ? AS millisecondsround
FROM TABLE1 e
WHERE id = ?");
$stmt->execute(array($minutes, $secondsrounded, $millisecondsround, $ID));





share|improve this answer













You can use placeholders in the SELECT list, and they'll be replaced with the values from the parameter array.



$stmt = $conn->prepare("
SELECT name, ? AS minutes, ? AS secondsrounded, ? AS millisecondsround
FROM TABLE1 e
WHERE id = ?");
$stmt->execute(array($minutes, $secondsrounded, $millisecondsround, $ID));






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 23:04









BarmarBarmar

436k36260365




436k36260365













  • Can you really do that?

    – Funk Forty Niner
    Nov 15 '18 at 23:05











  • Yes. Placeholders can be used wherever expressions are allowed. You can write SELECT 1 AS minutes FROM ...

    – Barmar
    Nov 15 '18 at 23:07











  • heh, interesting.

    – Funk Forty Niner
    Nov 15 '18 at 23:08











  • I actually have code that does something like this.

    – Barmar
    Nov 15 '18 at 23:08






  • 1





    And while I teach 99% of the time, every now and then I learn something new.

    – Barmar
    Nov 15 '18 at 23:10



















  • Can you really do that?

    – Funk Forty Niner
    Nov 15 '18 at 23:05











  • Yes. Placeholders can be used wherever expressions are allowed. You can write SELECT 1 AS minutes FROM ...

    – Barmar
    Nov 15 '18 at 23:07











  • heh, interesting.

    – Funk Forty Niner
    Nov 15 '18 at 23:08











  • I actually have code that does something like this.

    – Barmar
    Nov 15 '18 at 23:08






  • 1





    And while I teach 99% of the time, every now and then I learn something new.

    – Barmar
    Nov 15 '18 at 23:10

















Can you really do that?

– Funk Forty Niner
Nov 15 '18 at 23:05





Can you really do that?

– Funk Forty Niner
Nov 15 '18 at 23:05













Yes. Placeholders can be used wherever expressions are allowed. You can write SELECT 1 AS minutes FROM ...

– Barmar
Nov 15 '18 at 23:07





Yes. Placeholders can be used wherever expressions are allowed. You can write SELECT 1 AS minutes FROM ...

– Barmar
Nov 15 '18 at 23:07













heh, interesting.

– Funk Forty Niner
Nov 15 '18 at 23:08





heh, interesting.

– Funk Forty Niner
Nov 15 '18 at 23:08













I actually have code that does something like this.

– Barmar
Nov 15 '18 at 23:08





I actually have code that does something like this.

– Barmar
Nov 15 '18 at 23:08




1




1





And while I teach 99% of the time, every now and then I learn something new.

– Barmar
Nov 15 '18 at 23:10





And while I teach 99% of the time, every now and then I learn something new.

– Barmar
Nov 15 '18 at 23:10













1














Try this instead:



$stmt = $conn->prepare("SELECT name, millisecondstime FROM TABLE1 e
WHERE ID = :ID
ORDER BY millisecondstime ASC
");

$stmt->execute(array('ID' => $ID));





share|improve this answer
























  • It doesn't come from the table, it's a variable he set earlier in the script.

    – Barmar
    Nov 15 '18 at 23:00











  • Thanks, but if I add the other variables to the array, I'll get: Invalid parameter number: number of bound variables does not match number of tokens. I still need to set millisecondstime equal to those three variables. $stmt->execute(array('ID' => $ID, 'millisecondstime' => $minutes $secondsrounded $millisecondsround));

    – duke
    Nov 15 '18 at 23:00


















1














Try this instead:



$stmt = $conn->prepare("SELECT name, millisecondstime FROM TABLE1 e
WHERE ID = :ID
ORDER BY millisecondstime ASC
");

$stmt->execute(array('ID' => $ID));





share|improve this answer
























  • It doesn't come from the table, it's a variable he set earlier in the script.

    – Barmar
    Nov 15 '18 at 23:00











  • Thanks, but if I add the other variables to the array, I'll get: Invalid parameter number: number of bound variables does not match number of tokens. I still need to set millisecondstime equal to those three variables. $stmt->execute(array('ID' => $ID, 'millisecondstime' => $minutes $secondsrounded $millisecondsround));

    – duke
    Nov 15 '18 at 23:00
















1












1








1







Try this instead:



$stmt = $conn->prepare("SELECT name, millisecondstime FROM TABLE1 e
WHERE ID = :ID
ORDER BY millisecondstime ASC
");

$stmt->execute(array('ID' => $ID));





share|improve this answer













Try this instead:



$stmt = $conn->prepare("SELECT name, millisecondstime FROM TABLE1 e
WHERE ID = :ID
ORDER BY millisecondstime ASC
");

$stmt->execute(array('ID' => $ID));






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 22:48









DifsterDifster

3,06811730




3,06811730













  • It doesn't come from the table, it's a variable he set earlier in the script.

    – Barmar
    Nov 15 '18 at 23:00











  • Thanks, but if I add the other variables to the array, I'll get: Invalid parameter number: number of bound variables does not match number of tokens. I still need to set millisecondstime equal to those three variables. $stmt->execute(array('ID' => $ID, 'millisecondstime' => $minutes $secondsrounded $millisecondsround));

    – duke
    Nov 15 '18 at 23:00





















  • It doesn't come from the table, it's a variable he set earlier in the script.

    – Barmar
    Nov 15 '18 at 23:00











  • Thanks, but if I add the other variables to the array, I'll get: Invalid parameter number: number of bound variables does not match number of tokens. I still need to set millisecondstime equal to those three variables. $stmt->execute(array('ID' => $ID, 'millisecondstime' => $minutes $secondsrounded $millisecondsround));

    – duke
    Nov 15 '18 at 23:00



















It doesn't come from the table, it's a variable he set earlier in the script.

– Barmar
Nov 15 '18 at 23:00





It doesn't come from the table, it's a variable he set earlier in the script.

– Barmar
Nov 15 '18 at 23:00













Thanks, but if I add the other variables to the array, I'll get: Invalid parameter number: number of bound variables does not match number of tokens. I still need to set millisecondstime equal to those three variables. $stmt->execute(array('ID' => $ID, 'millisecondstime' => $minutes $secondsrounded $millisecondsround));

– duke
Nov 15 '18 at 23:00







Thanks, but if I add the other variables to the array, I'll get: Invalid parameter number: number of bound variables does not match number of tokens. I still need to set millisecondstime equal to those three variables. $stmt->execute(array('ID' => $ID, 'millisecondstime' => $minutes $secondsrounded $millisecondsround));

– duke
Nov 15 '18 at 23:00




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328858%2fphp-mysql-pdo-select-with-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues