简体   繁体   English

SQL / PHP如何从表中提取数据并将其放在变量中

[英]SQL / PHP How to pull data from a table and place it in variable

Assuming I have a uniqid key in my table and that same key is sent to my site in a get method, how do I pull that specific key out and assign all the data from the table to variables. 假设我的表中有一个唯一键,并且该键是通过get方法发送到我的站点的,那么我该如何拉出特定的键并将表中的所有数据分配给变量。 This is what I have so far but cant seem to figure it out. 这是我到目前为止所掌握的,但似乎无法弄清楚。

$query1 = "SELECT * 
       FROM todo_item2 as ti INNER JOIN todo_category2 as tc ON ti.todo_id = tc.todo_id'
       WHERE todo_id = :todo_id";

$statement1 = $db->prepare($query1);
$statement1 -> execute(array(
    'todo_id' =>$id
));

while ($row = $statement1->fetch()) 
{
    $text = $row['todo'];
    $cat = $row['category'];
    $percent = $row['precent'];
    $date = $row['due_date'];
}

You should ready about what execute actually does .. the parameters to execute (and I assume you're using PDO or something similar here) are the tokens of the query. 您应该准备好execute实际操作..要execute的参数(我假设您正在使用PDO或类似的东西)是查询的标记。 What you want is something like: 您想要的是这样的:

$query = " ... WHERE todo_id = ?"
$stmt = $db->prepare($query);
$stmt->execute(array($id));
while ($row = $stmt->fetch()) {
   //$row is now an associative array of row values.
}
// Start the Load
$query1 = "SELECT * 
           FROM todo_item2 as ti INNER JOIN todo_category2 as tc ON ti.todo_id = tc.todo_id
           WHERE ti.todo_id = :todo_id";

$statement1 = $db->prepare($query1);
$statement1 -> execute(array(
    'todo_id' =>$id
));

// Make Sure the Data Exists
if( $statement1->rowCount() == 0 )
{
    die('Please Enter a Valid ID Tag - (id)');
}


while($row = $statement1->fetch())
{
    $text = $row['todo'];
    $cat = $row['category'];
    $percent = $row['percent'];
    $date = $row['due_date'];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 table1 的 ID 中提取数据并通过 PHP 将其放入 table2 的 FOREIGN KEY - How to pull data from table1's ID and place it into table2's FOREIGN KEY via PHP 如何在使用PHP和SQL Server进行Ajax搜索之前从表中查看默认数据 - How to view default data from the table before ajax search takes place using php and sql server 如何使用Codeigniter或PHP从SQL Server API中提取数据 - how to pull data from sql server api using Codeigniter or PHP Php,拉出一个变量的占位符 - Php, pull place holders out of a variable 执行OPENQUERY来从MySql Server提取数据,并使用PDO从php脚本内部将其引导到SQL表? - Executing OPENQUERY to pull data from MySql Server and inner joing it to SQL table from php script using PDO? 从PHP将可变长度的数据发送到SQL表,是否有更好的方法? - Sending data of variable length to SQL table from PHP, is there a better way? php / sql-如何在变量上使用LIKE运算符从数据库中提取结果? - php/sql- How do I use LIKE operator on variable to pull results from database? 如何从不同的表中提取数据并使用php将其显示在同一页面的不同html表中? - how to pull data from different table and display it in different html table on a same page using php? 从SQL查询中提取行数并将其作为变量放入PHP? - Pull number of rows from a SQL query and put it in PHP as a variable? PHP 来自 sql 表的回波变量的变量 - PHP Variable from echo variable of sql table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM