[英]Assign values from an array to specific PHP variables
I am trying to use PHP to select values from a SQL Server DB and assign values to specific parameters.我正在尝试使用 PHP 从 SQL Server 数据库中选择值并将值分配给特定参数。
The table I am selecting from looks like this:我从中选择的表格如下所示:
**ColumnName1 ColumnName2**
DataRow1Col1, DataRow1Col2
DataRow2Col1, DataRow2Col2
DataRow3Col1, DataRow3Col2
DataRow4Col1, DataRow4Col2
I am trying to create a variable that will be equal to DataRow3Col2 which always has a ColumnName1 = DataRow3Col1.我正在尝试创建一个等于 DataRow3Col2 的变量,该变量始终具有 ColumnName1 = DataRow3Col1。
Is this possible?这可能吗?
Here is what I have so far:这是我到目前为止所拥有的:
$sql = "SELECT * FROM Table where id = {$ID}";
$stmt = sqlsrv_query( $trpConn, $sql );
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
$data = array();
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
$data[] = $row;
}
sqlsrv_free_stmt( $stmt);
Thank you谢谢
$sql = "SELECT * FROM Table where id = {$ID}";
$stmt = sqlsrv_query( $trpConn, $sql );
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );
}
$data = array();
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
$data[$row['ColumnName1']] = $row['ColumnName2'];
}
sqlsrv_free_stmt( $stmt);
extract($data);
echo $DataRow1Col1;
// The Output is: DataRow1Col2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.