PHP mysql_fetch_assoc只返回1

时间:2014-08-06 23:00:56

标签: php mysql solr

我有一个问题,我根本无法弄明白。每个"阵列" mysql_fetch_assoc返回的值为1.
我已经包含了我的大部分代码(它有点复杂,所以我在下面提供了解释),因为我不知道任何solr操作是否可能影响任何mysql_ *操作。

$server_details = array(
                        'hostname' => SOLR_SERVER_HOSTNAME,
                        'login' => SOLR_SERVER_USERNAME,
                        'password' => SOLR_SERVER_PASSWORD,
                        'port' => SOLR_SERVER_PORT,
                       );
//connect to mysql database
$db = 'name';
$db_connect = mysql_connect('localhost:3306', $db, getPassword($db));
$mysql_select_db($db, $db_connect);
$query = "SELECT * FROM table ORDER BY value ASC;";
$result = mysql_query($lss_query, $db_connect);

while($row = mysql_fetch_assoc($result))
    print_r($row);//this prints out all of my data, not ones.

//connect and make query for solr database
$solr_client = new SolrClient($server_details);
$solr_query = new SolrQuery();
$solr_query->setQuery('*:*');

//decide size of discretizations of solr and mysql databases
$query_interval = round(mysql_num_rows($result) / 10);
$counter = 0;
$solr_query->setRows($query_interval);

while($counter < mysql_num_rows($result))
{
    $sql_array = array(array());

    $base_counter = $counter;

    //query solr
    $solr_query->setStart($counter);
    $solr_response = $solr_client->query($solr_query);
    $solr_result_xml = $solr_response->getResponse();

    mysql_data_seek($result, $counter);
    while($row = mysql_fetch_assoc($result) && ($counter < $base_counter + $query_interval))
    {
       $counter++;
       print_r($row); //prints out a single 1 for each row
       //push each mysql into a 2-d array for further processing
       array_push($sql_array, $row);
    }
    //this function changes nothing
    generic_function($solr_result_xml, $sql_array);
    print_r($sql_array); //prints out a bunch of 1's
    unset($sql_array);
}

可能还有其他错误,但请包含手头问题的答案。我还没有完成调试,因为这个问题并没有找到那些问题,如果有的话 感谢

1 个答案:

答案 0 :(得分:1)

Precedence matters.

while(($row = mysql_fetch_assoc($result)) && ($counter < $base_counter + $query_interval))