Forum Moderators: coopster
What I am trying to do is group results by source, return the source only once (using DISTINCT?) and then group the details/summary in rows.
Here is my current code, the returns a row for each item...any suggestions are welcome!
<?php
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "
<tr>\n
<td>$source\n<br>
<td><a href='$story'>$details</a><br>
<td><a href='storyview2.php?id=$id'>$summary</a>
</td>\n
</tr>";
}
?>
Thanks!
won't it simply continue to repeat the 'source' row anyhow
Anything inside your loop is going to repeat so long as there are results. You want to stick with (X)HTML standards and close all of your tags. This will also make sure your code renders properly. In this case you would want your <table> and </table> tags outside of your loop so that they don't repeat with each iteration.
....particular item. Often, I have ten or more results from the same source
You're setting up a query for a unique item but you're getting multiple results? I'm not sure I follow you.
My hunch is that you should re-work your database architecture so that you can call source by unique id and then reference group with a foreign key using the unique id from source.
"Anything inside your loop is going to repeat so long as there are results. You want to stick with (X)HTML standards and close all of your tags. This will also make sure your code renders properly. In this case you would want your <table> and </table> tags outside of your loop so that they don't repeat with each iteration. "
So, closing my tags properly, and removing '$source' from my table, I might be able to do something like this (please forgive if the syntax is incorrect):
Select * from DB where date > today
(now for displaying)
$source
<table>
info /n
</table>
....particular item. Often, I have ten or more results from the same source
The top level source for the info might be *SPN or other site, and I might have 10 or so listings from that source.
Basically, ideally my page would render like this for example:
Source1: information-a
information-b
etc.
Source2: information-a
information-b
etc.
(as it is now, each row will include the source as well - it works, but is messy)