如何在php中获取数组中的所有数据?

How to get all the data in array in php?

我正在使用 phpmyadmin sql

中的查询
  select cm.contract_id,wd.day,cm.start_date, cm.start_time, cm.end_time from contract_master as cm left join contract_week_classes_master as cwcm on cwcm.contract_id =cm.contract_id left join week_days as wd on wd.id = cwcm.week_days where cm.tutor_institute_uid = 27 and cm.end_date >= curdate()

得到

contract_id     day     start_date  start_time  end_time    
1   Sun     2015-01-02  06:00:00    09:00:00
1   Mon     2015-01-02  06:00:00    09:00:00
1   Tue     2015-01-02  06:00:00    09:00:00
1   Wed     2015-01-02  06:00:00    09:00:00
1   Thu     2015-01-02  06:00:00    09:00:00
1   Fri     2015-01-02  06:00:00    09:00:00

在 php 中使用 print_r() 时仅查找 php页面查询

$rr[] = mysql_fetch_assoc(mysql_query("select cm.contract_id,wd.day,cm.start_date,cm.end_date, cm.start_time, cm.end_time from contract_master as cm
                                     left join contract_week_classes_master as cwcm on cwcm.contract_id =cm.contract_id   
                     left join week_days as wd on wd.id = cwcm.week_days
    where cm.tutor_institute_uid = '" . $_SESSION['user_id'] . "' and cm.end_date >= curdate()"));

并在 print_r($rr); 我得到

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => Sun
            [2] => 2015-01-02
            [3] => 2015-03-19
            [4] => 06:00:00
            [5] => 09:00:00
        )

)

请告诉我如何获取所有数据。

勾选php.net http://php.net/manual/en/function.mysql-fetch-assoc.php

要获取所有行,您应该使用

$result = mysql_query(" ... ");
$rr = array();
while ($row = mysql_fetch_assoc($result)) {
    $rr[] = $row;
}
print_r($rr);

现在您只能看到第一行。 P.S。还可以考虑使用 mysqli 而不是 mysql.