Forum Moderators: coopster

Message Too Old, No Replies

'Unique' display of source

         

dave1236

5:35 pm on Jul 20, 2007 (gmt 0)

10+ Year Member



I am trying to improve the display of my content. Currently, I query my DB and pull out the source, details, and summary for a particular item. Often, I have ten or more results from the same source. As such, my page looks cluttered.

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!

justgowithit

7:59 pm on Jul 20, 2007 (gmt 0)

10+ Year Member



Dave, you're not closing your table cells.... or am I reading it wrong?


<tr>\n
<td>$source</td>\n
<td><a href='$story'>$details</a></td>
<td><a href='storyview2.php?id=$id'>$summary</a></td>\n

</tr>";

dave1236

9:26 pm on Jul 20, 2007 (gmt 0)

10+ Year Member



You are reading it right. if i correct that error, won't it simply continue to repeat the 'source' row anyhow?

dave1236

9:29 pm on Jul 20, 2007 (gmt 0)

10+ Year Member



as a further note, in my query, i select * from my DB.

maybe i should do something like select DISTINCT source? but hten how do i get the complete rest of records?

justgowithit

3:39 pm on Jul 22, 2007 (gmt 0)

10+ Year Member



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.

dave1236

1:28 am on Jul 27, 2007 (gmt 0)

10+ Year Member



Thanks for the comments....

"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)