gpt4 book ai didi

php循环和mysql分组

转载 作者:行者123 更新时间:2023-11-29 15:00:36 25 4
gpt4 key购买 nike

我目前正在向支付系统添加购买历史记录部分,该系统是用PHP(codeigniter框架)和mysql构建的。付款历史记录部分的想法是所有客户购买都按日期分组在一起,因此最终 HTML 看起来与此类似,

我的问题是我可以毫无问题地从数据库中获取数据,但是我如何循环它以便显示购买日期,然后显示与该日期相关的购买等等。

编辑 - 从数据库返回的数组的打印,抱歉,大小

    Array
(
[0] => Array
(
[id] =>
[employer_id] => 1
[cv_id] =>
[transaction_id] => -1402310
[date_created] => 20-07-10
[date_updated] =>
[code] => 849711492
[status] => SHOW
[is_complete] => TRUE
[job_status] => 1
[dob] =>
[will_relocate] => Y
[education_level] => HIGH_SCHOOL
[job_looking_for] =>
[keywords_education] => Halifax University
[keywords_employment] => senior applications developer
[self_description] =>
[looking_for] => Lorem ipsum
[sector_id_csv] => 10,23,14,6,3
[key_skills_csv] =>
[expected_salary_level] => LEVEL_6
[expected_salary_low] => 0
[expected_salary_high] => 0
[best_salary_low] => 0
[best_salary_high] => 0
[last_job_salary_low] =>
[last_job_salary_high] =>
[last_job_title_1] => Designer
[last_job_title_2] =>
[last_job_employer_1] => BT
[last_job_employer_2] =>
[qual_highest_level] => 0
[is_grad] => Y
[is_contract] => N
[is_temporary] => Y
[is_permanent] => Y
[is_full_time] => Y
[is_part_time] => Y
[logitude] =>
[latitude] =>
[city] =>
[area] =>
[sign_up_stages_completed] =>
[sign_up_last_stage_completed] =>
[sign_up_complete] =>
[email_authenticated] =>
[email] =>
[email_contact] =>
[phone_contact_number] =>
[password] =>
[firstname] =>
[surname] =>
[address_1] =>
[address_2] =>
[address_3] =>
[postcode] =>
[country] =>
)

[1] => Array
(
[id] =>
[employer_id] => 1
[cv_id] =>
[transaction_id] => -1402310
[date_created] => 20-07-10
[date_updated] =>
[code] => 849719383
[status] => SHOW
[is_complete] => TRUE
[job_status] => 1
[dob] =>
[will_relocate] => Y
[education_level] => HIGH_SCHOOL
[job_looking_for] =>
[keywords_education] => Crewe Art School
[keywords_employment] => senior applications developer
[self_description] =>
[looking_for] => Lorem ipsum
[sector_id_csv] => 13,24,7,17,5
[key_skills_csv] =>
[expected_salary_level] => LEVEL_6
[expected_salary_low] => 0
[expected_salary_high] => 0
[best_salary_low] => 0
[best_salary_high] => 0
[last_job_salary_low] =>
[last_job_salary_high] =>
[last_job_title_1] => Developer
[last_job_title_2] =>
[last_job_employer_1] => Orange
[last_job_employer_2] =>
[qual_highest_level] => 0
[is_grad] => Y
[is_contract] => N
[is_temporary] => Y
[is_permanent] => Y
[is_full_time] => Y
[is_part_time] => N
[logitude] =>
[latitude] =>
[city] =>
[area] =>
[sign_up_stages_completed] =>
[sign_up_last_stage_completed] =>
[sign_up_complete] =>
[email_authenticated] =>
[email] =>
[email_contact] =>
[phone_contact_number] =>
[password] =>
[firstname] =>
[surname] =>
[address_1] =>
[address_2] =>
[address_3] =>
[postcode] =>
[country] =>
)

[2] => Array
(
[id] =>
[employer_id] => 1
[cv_id] =>
[transaction_id] => 23-9-1402338
[date_created] => 17-07-10
[date_updated] =>
[code] => 849711492
[status] => SHOW
[is_complete] => TRUE
[job_status] => 1
[dob] =>
[will_relocate] => Y
[education_level] => HIGH_SCHOOL
[job_looking_for] =>
[keywords_education] => Halifax University
[keywords_employment] => senior applications developer
[self_description] =>
[looking_for] => Lorem ipsum
[sector_id_csv] => 10,23,14,6,3
[key_skills_csv] =>
[expected_salary_level] => LEVEL_6
[expected_salary_low] => 0
[expected_salary_high] => 0
[best_salary_low] => 0
[best_salary_high] => 0
[last_job_salary_low] =>
[last_job_salary_high] =>
[last_job_title_1] => Designer
[last_job_title_2] =>
[last_job_employer_1] => BT
[last_job_employer_2] =>
[qual_highest_level] => 0
[is_grad] => Y
[is_contract] => N
[is_temporary] => Y
[is_permanent] => Y
[is_full_time] => Y
[is_part_time] => Y
[logitude] =>
[latitude] =>
[city] =>
[area] =>
[sign_up_stages_completed] =>
[sign_up_last_stage_completed] =>
[sign_up_complete] =>
[email_authenticated] =>
[email] =>
[email_contact] =>
[phone_contact_number] =>
[password] =>
[firstname] =>
[surname] =>
[address_1] =>
[address_2] =>
[address_3] =>
[postcode] =>
[country] =>
)

[3] => Array
(
[id] =>
[employer_id] => 1
[cv_id] =>
[transaction_id] => 23-9-1402338
[date_created] => 17-07-10
[date_updated] =>
[code] => 849719383
[status] => SHOW
[is_complete] => TRUE
[job_status] => 1
[dob] =>
[will_relocate] => Y
[education_level] => HIGH_SCHOOL
[job_looking_for] =>
[keywords_education] => Crewe Art School
[keywords_employment] => senior applications developer
[self_description] =>
[looking_for] => Lorem ipsum
[sector_id_csv] => 13,24,7,17,5
[key_skills_csv] =>
[expected_salary_level] => LEVEL_6
[expected_salary_low] => 0
[expected_salary_high] => 0
[best_salary_low] => 0
[best_salary_high] => 0
[last_job_salary_low] =>
[last_job_salary_high] =>
[last_job_title_1] => Developer
[last_job_title_2] =>
[last_job_employer_1] => Orange
[last_job_employer_2] =>
[qual_highest_level] => 0
[is_grad] => Y
[is_contract] => N
[is_temporary] => Y
[is_permanent] => Y
[is_full_time] => Y
[is_part_time] => N
[logitude] =>
[latitude] =>
[city] =>
[area] =>
[sign_up_stages_completed] =>
[sign_up_last_stage_completed] =>
[sign_up_complete] =>
[email_authenticated] =>
[email] =>
[email_contact] =>
[phone_contact_number] =>
[password] =>
[firstname] =>
[surname] =>
[address_1] =>
[address_2] =>
[address_3] =>
[postcode] =>
[country] =>
)

)

基本上每次有新数据时,我都需要列出其下数组的内容,如果两个数组具有相同的数据,则将它们列在一个数据下,例如,

10-07-30

结果1
2
3

28-7-10

4
5

最佳答案

使用 CodeIgniter,循环查询结果的一种方法如下:

//if your doing your queries in a controller
$data['query']=$this->db->query('SELECT * FROM purchases WHERE clientID=5');

//or if using models
$data['query']=$this->pmnt_model->getPmnts();

//view
foreach($query result() as $row){
echo $row->date;
}

$query变量是mysql查询返回的结果数组。可以通过 -> 运算符访问这些对象。

参见http://codeigniter.com/user_guide/database/results.html了解更多信息。

您可能还想查看the active record class .

HTH

关于php循环和mysql分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3265297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com