我有一个表,其中的值来自dat_eb_registrants
行(例如$row[1]
)和来自水平数组的值,从 中提取dat_eb_field_values
,我想将它们拆分,以便我可以按照我想要的方式将所有内容排序到表中。
数据如何放入我的表中:
$count = 0;
while ($row = mysql_fetch_row($result))
{
echo "<tr>";
$myArray[] ="<tr><td>" . $row[9] . "</td><td>"; echo $myArray[$count];
$count++;
echo "</tr>";
}
如何从数据库中提取所有数据(是的,我知道它很旧):
SELECT dr.id, dr.first_name, dr.last_name, dr.email, dr.comment, dr.amount, dr.published, dr.transaction_id, dr.register_date, GROUP_CONCAT(df.field_value SEPARATOR '</td><td>')
FROM dat_eb_registrants dr
LEFT JOIN dat_eb_field_values df
ON dr.id=df.registrant_id
WHERE `event_id` >= 20 AND `event_id` <= 25
GROUP BY dr.id
ORDER BY '".$sort."', '".$ascdsc."'
现在,我想将第一个表(例如$row[1]
)和(例如)中的一些行$row[2]
垂直放在数组的中间。我怎样才能做到这一点?
因为数组一次性填满了我的表,并且使用$rows
,您可以简单地告诉哪些行显示在哪里......
这就是我想要的(代码可能不正确):
while ($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>"'.$row_table_1[1]'"</td>";
echo "<td>"'.$row_table_1[2]'"</td>";
echo "<td>"'.$row_table_2[35]'"</td>";
echo "<td>"'.$row_table_2[45]'"</td>";
echo "<td>"'.$row_table_1[5]'"</td>";
echo "<td>"'.$row_table_2[6]'"</td>";
echo "</tr>";
}
我曾经做:
echo "<td>"; $result24 = mysql_query("SELECT field_id, field_value FROM dat_eb_field_values WHERE (field_id = 88) AND (registrant_id = $row[0])"); $r24 = mysql_fetch_row($result24); echo $r24[1]; echo "</td>";
echo "<td>"; $result25 = mysql_query("SELECT field_id, field_value FROM dat_eb_field_values WHERE (field_id = 57) AND (registrant_id = $row[0])"); $r25 = mysql_fetch_row($result25); echo $r25[1]; echo "</td>";
echo "<td>" . $row[5] . "</td>";
echo "<td>" . $row[6] . "</td>";
我想要做:
echo "<td>" . $rowfromsecondtable[1] . "</td>";
echo "<td>" . $rowfromsecondtable[2] . "</td>";
echo "<td>" . $row[5] . "</td>";
echo "<td>" . $row[6] . "</td>";
(使用我上面给出的代码)
预览dat_eb_registrants
:
| id | first_name | last_name | email |
------------------------------------------------------------------------
| 1 | Mike | Doe | mikedoe@hotmail.com |
| 2 | John | Smith | j_smith@hotmail.com |
预览dat_eb_field_values
:
field 1 = fav.sport
field 2 = fav. color
field 3 = fav. food
| registrant_id | field_id | field_value |
----------------------------------------------------------
| 1 | 1 | tennis |
| 1 | 2 | green |
| 1 | 3 | spagetti |
| 2 | 1 | hockey |
| 2 | 2 | red |
| 2 | 3 | fish |
我需要:
first_name | id | fav.sport | last_name | fav.food |
---------------------------------------------------------------------
Mike | 1 | Tennis | Doe | spagetti |
John | 2 | Hockey | Smith | fish |