这个想法是在javascript变量中获取由mysql查询提供的数组。它工作正常,但变量的结果显示比查询减1行。
下面我提供了代码引用问题,跳过所有其余的,我想是不需要的。
提前感谢您的帮助!
查询:
$search_qryvalAltnsRotas = "-1";
if (isset($_GET['search'])) {
$search_qryvalAltnsRotas = $_GET['search'];
}
mysql_select_db($database_connect, $connect);
$query_qryvalAltnsRotas = sprintf("SELECT altn, destino FROM tblalternativos WHERE destino = %s ORDER BY destino ASC", GetSQLValueString($search_qryvalAltnsRotas, "text"));
$qryvalAltnsRotas = mysql_query($query_qryvalAltnsRotas, $sado_leitor) or die(mysql_error());
$row_qryvalAltnsRotas = mysql_fetch_assoc($qryvalAltnsRotas);
$totalRows_qryvalAltnsRotas = mysql_num_rows($qryvalAltnsRotas);
下面的(...)是变量(javascript函数的一部分):
var alternatesq =
<?php
while( $row_qryvalAltnsRotas = mysql_fetch_assoc($qryvalAltnsRotas) ) {
$alternates[] = $row_qryvalAltnsRotas['altn'];
}
echo json_encode( $alternates );
?>;
答案 0 :(得分:3)
因为您已拨打mysql_fetch_assoc
两次,请删除此行
$row_qryvalAltnsRotas = mysql_fetch_assoc($qryvalAltnsRotas);
只使用这个
while( $row_qryvalAltnsRotas = mysql_fetch_assoc($qryvalAltnsRotas) )