Hi. Hoping someone can help. From what I've researched I think I need to use a multidimensional array but I'm not getting my head around this problem so there might be another way.
I'm building a basic web app. It's a mysql database of links to county record offices nationwide. Each link is accompanied by info like who last researched the link and when, as well as a note for the next user. So this table is several rows deep, is indexed, and has two LEFT JOIN
in the query to merge the user and note with the link.
For visual purposes I want to divide this list by state. So for every different state a header with the state name injects itself between the rows. How do I get my while($row = mysql_fetch_array($results)
to subdivide by state? I started to look at using foreach()
as a nested loop but spent hours without any luck.
Thanks for any help. First time posting, so if you need more info or anything, let me know. Here's my code below. I stripped out all the formatting stuff to make it more legible, but if I left a closing div or span tag or something somewhere please ignore it. That said, if you see anything else you think my help my code be better or simpler, please let me know.
$query = "SELECT sites.url, sites.site_id, sites.description, sites.state, sites.date, sites.appender_id, notes.comment, notes.author_id, notes.tstamp, users.user_id, users.firstName, users.lastName, users2.firstName AS authorFirstName, users2.lastName AS authorLastName, users2.user_id FROM sites LEFT JOIN users ON sites.appender_id = users.user_id LEFT JOIN notes ON sites.site_id = notes.site LEFT JOIN users AS users2 ON notes.author_id = users2.user_id ORDER BY sites.state sites.description";
};
$result = mysql_query($query)
or die(mysql_error());
while($row = mysql_fetch_array($result)){
// make a layout for each result
echo $row['state'];
echo "<a href='".$row['url']."' target='_blank'> ".$row['url']."</a>";
// show the site description and info for last appending.
echo "Site Description: ".$row['description']." | ";
echo "Last Appended on: ".$row['date']." | by ".$row['firstName']." ".$row['lastName'];
// show latest note for this site. If no note, skip it.
if ($row['comment'] != null) {
// Who wrote the last note and when
echo "Last Note on: ".$row['tstamp']." By: ".$row['authorFirstName']." ".$row['authorLastName']."<br />";
// the note
echo $row['comment'];
}
}