[英]PHP Unable to echo ID field from MySQL database
I'm trying to print an ID from MySQL, the field loads into an array and is visible via print_r but I can't echo it or transfer it to another variable ... what am I missing? 我正在尝试从MySQL打印一个ID,该字段加载到一个数组中,并且可以通过print_r看到,但是我无法回显它或将其传递给另一个变量……我缺少什么?
if ( $_POST['section'] == "freelance" ) {
$field_name = "promoter";
} else {
$field_name = "connector";
}
echo $row[$field_name.'_login_ID']
As requested the results of var_dump($row) 根据要求var_dump($ row)的结果
array(13) {
["connector_login_id"] => string(2) "14"
["connector_type"] => string(10) "non-profit"
["unique_code"] => string(9) "test-t001"
["update_code"] => string(1) "N"
["md5ID"] => string(0) ""
["username"] => string(6) "bugger"
["connectorEmail"] => string(17) "gzigner@gmail.com"
["password"] => string(32) "098f6bcd4621d373cade4e832627b4f6"
["connectorPass"] => string(4) "test"
["active"] => string(1) "Y"
["modified"] => string(19) "2009-08-21 15:37:22"
["lastlogin"] => string(19) "0000-00-00 00:00:00"
["md5email" ]=> string(32) "051cba58da33fac6b2d18af5182079f4"
}
$row[$field_name.'_login_ID'] <-- "ID"
array(13) {
["connector_login_id"] <-- "id"
Seems like a simple typo to me. 对我来说似乎是一个简单的错字。
Alternatively, are you sure $field_name
gets set to 'connector'
, since 'promoter_login_id'
doesn't exist in this array. 或者,您确定
$field_name
被设置为'connector'
,因为此数组中不存在'promoter_login_id'
。
This is purely speculation without your code, but it's probable that the field you are trying to echo contains a hyphen, eg "mytable-id", considering that it does indeed show when you use print_r() to print out the entire array. 这纯粹是在没有代码的情况下进行的推测,但是您尝试回显的字段可能包含连字符,例如,“ mytable-id”,考虑到当您使用print_r()打印出整个数组时确实会显示连字符。 If this is the case you would need to use {'mytable-id'} to get/echo it's value:
如果是这种情况,则需要使用{'mytable-id'}来获取/回显其值:
echo($dataArray->MyTable->{'mytable-id'});
*Edit : I don't know if your code is copy and pasted, but the value you are trying to print is: *编辑 :我不知道您的代码是否已复制并粘贴,但是您要打印的值是:
echo $row[$field_name.'_login_ID'];
instead of: 代替:
echo $row[$field_name.'_login_id'];
PHP is case-sensitive. PHP区分大小写。 You could also try this:
您也可以尝试以下方法:
$field_name = $field_name.'_login_id';
echo $row[$field_name];
or 要么
$field_name = $field_name.'_login_id';
echo $row['$field_name'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.