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))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了