我想显示我的数组的值。但不是显示:
1509 1510 1511 显示 ArrayArrayArray 。这是什么意思?
include("db_PSIS.php");
$sql_dc = "SELECT Child, Datecode
FROM traveller_merging15
WHERE Parent='" . $_REQUEST["txt_traveller_no"] . "'
ORDER BY Merge_ID ASC";
$res_dc = mysql_query($sql_dc);
$dcode1 = $row_dc['Datecode'];
$storeArray = array();
if (!$res_dc) {
echo "No data fetched!";
} else {
while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
$storeArray[] = $dcode1;
echo "{$storeArray} <br>";
}
//$str_dc=implode(",",$storeArray);
//echo $str_dc;
}
答案 0 :(得分:1)
在从数据库中获取数据之前,您将分配$row_dc['Datecode'];
的值。你需要做fetch data inside while loop
并回复它
$res_dc = mysql_query($sql_dc);
if (!$res_dc) {
echo "No data fetched!";
} else {
while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
echo $row_dc['Datecode'];
}
}
注意: - 不推荐使用mysql而是使用mysqli或PDO
答案 1 :(得分:0)
else {
while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
$storeArray[] = $dcode1;
echo "{$storeArray} <br>";
}
而不是尝试
else {
while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
$storeArray[] = $dcode1;
echo "{$storeArray[0]} <br>";
}
答案 2 :(得分:0)
试试这个,
else {
while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
$child = $row_dc['Child'];
$Datecode = $row_dc['Datecode'];
echo "$child <br> $Datecode";
}
如果您获得的行数超过1行,请使用for()
循环
else {
while ($row_dc = mysql_fetch_array($res_dc, MYSQL_ASSOC)) {
$count = count($row_dc);
for($i = 0; $i < $count; $i ++){
$child = $row_dc[$i]['Child'];
$Datecode = $row_dc[$i]['Datecode'];
echo "$child <br> $Datecode";
}
}
答案 3 :(得分:0)
-first 数组不使用 echo 打印值
-use print_r($ array)打印键值对(打印数组)
你的解决方案是
2015-11-23 08:35:42.927 a.out[91256:5691654] 1
2015-11-23 08:35:42.930 a.out[91256:5691654] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do regex matching on object (
).'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff88e8ee32 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff872284fa objc_exception_throw + 48
2 Foundation 0x00007fff8e2ac62f -[NSMatchingPredicateOperator performPrimitiveOperationUsingObject:andObject:] + 498
3 Foundation 0x00007fff8e212dd7 -[NSPredicateOperator performOperationUsingObject:andObject:] + 286
4 Foundation 0x00007fff8e212b8d -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 313
5 a.out 0x0000000101a8decf main + 159
6 libdyld.dylib 0x00007fff86c4c5ad start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
[1] 91256 abort ./a.out
注意:: - 使用单引号而不是双引号而不推荐使用mysql代替使用mysqli或PDO