I hope you guys can help me, basically...
I have 2 database tables (note: the U & B here are my particular fields of interest - the id and fk_id are the PK and FK)
(main)Table 1 gives the MAIN_TITLES (id, TITLE, positioning, created, modified)
(list)Table 2 (id, FK_ID(= T1 id), subTITLE, positioning, created, modified) is a list set, organised by a FK, and takes its main_title from Table 1
would look something like this
T1 - t2, t2, t2
T1 - t2, t2, t2, t2, t2
T1 - t2, t2, t2, t2
T1 - t2, t2, t2, t2, t2, t2, t2 t2, t2
T1 - t2, t2, t2, t2
Hopefully this is clear enough.... and so my code is:
$get_main_title = mysqli_query($mysqli, "SELECT * FROM table_1") or trigger_error (mysqli_error($mysqli));
while($row_main = mysqli_fetch_array($get_main_title)) {
$main_id = $row_main['id'];
$main_title = $row_main['title'];
// Draw the Title and open div
$display_block = "<h1>".$main_title."</h1>";
$display_block .= "<div..>";
// Draw the Contents
$get_list_title = mysqli_query($mysqli, "SELECT * FROM table_2 WHERE fk_id = $main_id") or trigger_error (mysqli_error($mysqli));
while($row_list = mysqli_fetch_array($get_list_title)) {
$list_title = $row_list['title'];
$display_block .= "<p>".$list_title."</p>";
}
// Draw close div
$display_block .= "</div>";
}
Pre-empting the what errors qs - there are none, but the main problem is that I am only getting the last row from table_1, and its associted table_2 rows from that table_1.
I'm thinking a foreach (row as key), but this is the help I need. (The above code is my entire code, so I really would appreciate a quick code fix, and then I'll kick myself good and hard), I'm sure it's a 3 or 4 line fix.
Thank you - mo!