Hi there, I am trying to get the following table outputted from my database with all the values etc., here is what I want it to look like:
Where organism, family and protein are fields in a database.
This is what I have got so far (I have got the sql sorted), but it looks completely wrong:
I'm not even sure I am going about it the right way, any help would be very much appreciated, thanks, Chris.
Code:
<table id="mytable" cellspacing="0" summary="Database Overview">
<caption>Table 1:Database Overview </caption>
<tr>
<th>Family Name</th>
<th>Organism1</th>
<th>Organism2</th>
<th>Organism3</th>
</tr>
<tr>
<th>Family1</th>
<td>Protein1</td>
<td>Protein2</td>
<td>Protein3</td>
</tr>
<tr>
<th>Family2</th>
<td>Protein3</td>
<td>Protein4</td>
<td>Protein5</td>
</tr>
</table>
Where organism, family and protein are fields in a database.
This is what I have got so far (I have got the sql sorted), but it looks completely wrong:
Code:
if (mysql_num_rows($subresult) == 0)
{
echo "no data";
}
else
{
echo "
<table id='mytable' cellspacing='0' summary='Database Overview'>
<caption>Table 1:Database Overview </caption>
<tr>
<th>Family</th>
";
$familyid = -1;
$organismid = -1;
while ($row = mysql_fetch_assoc($subresult))
{
if ($organismid != $row['organism_id'])
{
if ($organismid == -1)
{
echo "";
}
echo "<th>" . $row['organism'] ."</th>";
$familyid = $row['family_id'];
$organismid = -1;
}
if ($familyid != $row['family_id'])
{
echo "<th>" . $row['family'] . "</th>";
$familyid = $row['family_id'];
}
else
{
echo "</tr>";
}
echo "<td><a href='protein.php?id=" . $row['id'] . "'>" . $row['name'] . "</a></td>";
}
echo "
</tr>
</table>
";
}
I'm not even sure I am going about it the right way, any help would be very much appreciated, thanks, Chris.