且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL-如何显示邮件表中的所有记录,而不仅仅是一个

更新时间:2022-06-14 23:16:44

您的问题是您仅选择

WHERE fms_opslagpm.id = ?

因此,在id上有完全匹配项的情况下,它将仅返回1行.看起来像您在尝试选择与id

So it will only return 1 row where there is an exact match on the id. It looks like you where trying to also select the rows that have the same title as the row with the id

GROUP BY fms_opslagpm.title

但是,即使您返回的行多于1行,这也会再次将结果折叠为1行.

but even if you returned more than 1 row, this would have collapsed the results into 1 row again.

您需要更改查询以获取行WHERE fms_opslagpm.id = ?title,并使用OR选择具有相同title的所有其他行.

You need to change your query to get the title of the row WHERE fms_opslagpm.id = ?, and using OR select all the other rows with the same title.

尝试-

SELECT 
  fms_bruger.fornavn, 
  fms_bruger.efternavn, 
  fms_opslagpm.id, 
  fms_opslagpm.title, 
  fms_opslagpm.besked
FROM fms_bruger 
INNER JOIN fms_opslagpm ON fms_bruger.id=fms_opslagpm.fra_id 
WHERE (
       fms_opslagpm.id = ? 
       OR fms_opslagpm.title = (
                                SELECT fms_opslagpm.title 
                                FROM fms_opslagpm 
                                WHERE fms_opslagpm.id = ?
                                ) 
       ) 
       AND 
       (
       fms_opslagpm.fra_id = ? 
       OR
       fms_opslagpm.til_id = ? 
       )

ORDER BY fms_opslagpm.datotid DESC

请参阅此SQLFiddle示例- http://sqlfiddle.com/#!2/36d534/6

See this SQLFiddle example - http://sqlfiddle.com/#!2/36d534/6

您还需要在bind_param

$stmt->bind_param('iiii', $id, $id1, $fra_id, $til_id);
                $id = $_GET["id"];
                $id1 = $_GET["id"];
                $fra_id = $_SESSION["id"];
                $til_id = $_SESSION["id"];