[英]get column name and values in array at same time from mysql in php
I am looking out for some kind of short code where i should not be repeating the column names
in database and it should directly be inserted with respective column name
index to array value
.我正在寻找某种短代码,我不应该在其中重复数据库中的
column names
,而应该直接将其与相应的column name
索引一起插入到array value
中。 Below i have uploaded the image for understanding.下面我上传了图片以供理解。
Use mysql_fetch_assoc()
rather than mysql_fetch_row()
and the array will be associative (using the column names as the key) rather than numeric.使用
mysql_fetch_assoc()
而不是mysql_fetch_row()
并且数组将是关联的(使用列名作为键)而不是数字。
$query = mysql_query("SELECT * FROM users_table WHERE User_ID = 1");
while ($r1 = mysql_fetch_assoc($query))
{
echo $r1['User_ID'] . ': ' . $r1['First_Name'] . ' ' . $r1['Last_Name'] . '<br />';
}
Check this:检查这个:
$query = mysql_query( "SELECT * FROM users_table WHERE user_id=1;" );
$row = mysql_fetch_array( $query );
print_r( $row );
more about mysql_fetch_array on php.net更多关于 php.net 上的mysql_fetch_array
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.