我有句子表:
======================================================================
| id_row | id_document | id_sentence | sentence |
======================================================================
| 1 | 1 | 0 | Example sentences A |
| 2 | 1 | 1 | Example sentences B |
| 3 | 2 | 0 | Example sentences C |
| 4 | 2 | 1 | Example sentences D |
======================================================================
我想将具有相同 id_document 的句子合并到数组中,例如 =>Array( [1] => Array ( [0] => Example sentences A [1] => Example sentences B ) [2] => Array ( [0] => Example sentences C [1] => Example sentences D ))
这是代码:
<?php
require_once 'conf.php';
$sql = mysql_query('SELECT sentence FROM sentence group by id_document') or die(mysql_error());
while ($row = mysql_fetch_array($sql)) {
$sentence[] = $row['sentence'];
}
print_r($sentence);
?>
但是,我只在每个不同的 id_document 中得到一个句子。帮我。谢谢 :)