dongyue0225 2014-08-06 23:00
浏览 47
已采纳

PHP mysql_fetch_assoc只返回1

I have a problem here that I simply cannot figure out. Every "array" returned by mysql_fetch_assoc has the value of 1.
I have included a majority of my code (it is slightly complex, so I have offered an explanation below) because I don't know if any solr actions could possibly affect any mysql_* actions.

$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);
}

It is possible there are other errors, but please contain answers to the question at hand. I have not finished debugging because of this problem and haven't found those problems yet, if there are any.
Thanks

  • 写回答

1条回答 默认 最新

  • dskzap8756 2014-08-06 23:02
    关注

    Precedence matters.

    while(($row = mysql_fetch_assoc($result)) && ($counter < $base_counter + $query_interval))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写