【发布时间】:2014-11-30 17:02:35
【问题描述】:
我正在尝试显示在反映办公室所在州的标题下排序的一组办公室,如下所示:
State
Office
Office
...
State
Office
...
我反对这个已经有一段时间了。 MySQL 数据库中有一个表“offices”,其中每个办公室的状态都列在“office_state”下。这是我想出的 - 但没有返回任何内容。
// Here I return a list of the distinct States:
$stateQuery = 'SELECT DISTINCT office_state AS state FROM offices';
$stateResult = mysql_query($stateQuery);
// Here I return each office's information:
$officeQuery = 'SELECT office_information, office_state FROM offices';
$officeResult = mysql_query($officeQuery);
// And here's where I'm stuck:
while ($rows = mysql_fetch_assoc($stateResult)) {
// This returns the distinct States:
echo $rows['state'];
// Here is my effort at listing each office within the State:
$rows1 = mysql_fetch_assoc($officeResult);
if ($rows['state'] == $rows1['office_state']) {
echo $rows1['office_information'];
}
}
任何帮助将不胜感激。
【问题讨论】:
-
什么都不返回在哪里?你在检查错误吗?