search
HomeBackend DevelopmentPHP TutorialPHP分组查询生成XML,该如何解决

PHP分组查询生成XML
有这样两张表,arp_individual是病人信息表,arp_area是住院房间表,现在要实现按房间统计病人数情况生成一个XML文档以便被flash动画调用,病人信息中的room字段与住院房间表中的id关联,怎么实现这样的PHP代码:

------------------------

以下是病人信息表

CREATE TABLE `arp_individual` (<br />  `id` int(11) NOT NULL default '0',<br />  `individualid` varchar(60) character set latin1 default NULL,<br />  `sex` int(11) default NULL,<br />  `room` int(11) default NULL,<br />  PRIMARY KEY  (`id`)<br />) ENGINE=MyISAM DEFAULT CHARSET=utf8;


------------------------

以下是住院房间表

CREATE TABLE `arp_area` (<br />  `id` mediumint(8) NOT NULL auto_increment,<br />  `areaname` longtext,<br />  `nurse` int(11) default NULL,<br />  PRIMARY KEY  (`id`)<br />) ENGINE=MyISAM AUTO_INCREMENT=2059 DEFAULT CHARSET=utf8;


------------------------

以下是生成的XML数据格式

<?xml version="1.0" encoding="utf-8"?><br /><data><br />	<area id="A01" title="常规治疗1区" value="常规治疗1区,人数:6人,护士:林晓岚" /><br />	<area id="A02" title="常规治疗2区" value="常规治疗1区,人数:5人,护士:林晓岚" /><br />	......<br />	<area id="F09" title="急诊9区" value="急诊9区,人数:8人,护士:张梅颖" /><br /></data>

------解决方案--------------------
DOMDocument生成
另没有看出来这两张表是怎么关联的,推测可能有第三张表吧。
------解决方案--------------------
还在搞医院的东西,我以前做过医院的单。
有几个经验:
1 私人医院全tmd 的奸商,要有一定的尺度,不要被人忽悠得到处转。
2 公立医院,资金要等好久,审批程序极期麻烦。
所以劝一句,没有很NB的关系,医院这趟水,没要涉太深~
------解决方案--------------------
为啥要like呢?
SELECT COUNT(*), areaname  FROM arp_individual i<br />  LEFT JOIN arp_area  a ON  i.room = a.id  <br />  GROUP BY i.room
 
------解决方案--------------------
如果希望别人帮你写代码,你至少需要:
1、给出表间关系
2、输出结果中的内容与字段的对应关系
------解决方案--------------------

引用:
上边忘记补充一点,其实房间编号信息里隐藏着房间的分类信息,像A01-01横杠后边的是房间编号,前边的A01是区域编号,这不是我这样设计的,医院本身就这样编号,没办法!

先统计单个的,然后再循环处理A01-01这种情况。字符串操作总比mysql要来的容易些。~
------解决方案--------------------
既然你连数据对应关系都不愿提供,那只有泛泛的说了
按病区计数、求和,将结果循环输出
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)