I have this PHP in my application,
<table><tr>
<?php
if($music_interests !== FALSE)
{
$count = 0;
foreach($music_interests as $interest)
{
?>
<td>
<div class="interest inline">
<img src="<?php echo $interest['image']; ?>" alt="<?php echo truncate($interest['name'], 25); ?>" class="interest_img"/>
<p><?php echo truncate($interest['name'], 25); ?></p>
<div class="interest_popup">
<img src="<?php echo $interest['image']; ?>" alt="<?php echo truncate($interest['name'], 25); ?>" class="interest_img left"/>
<div class="right">
<strong><?php echo truncate($interest['name'], 25); ?></strong>
<p>Music<br><?php echo @$interest['num_users']; ?> users have this interest.</p>
<?php echo anchor('my_profile/remove_interest/'.$interest['id'], 'Remove interest', array('class' => 'button red upper rounded_5 small remove')); ?>
</div>
<div class="clear"></div>
</div><!--.interest_popup-->
</div>
</td>
<?php
$count = ($count + 1)%4;
if ($count == 0)
{
echo "</tr><tr>";
}
}
}
?>
As you can see the PHP creates a table and every 4th <td>
creates a new row. I am now adding ajax functionality to my app, but I cannot work out how I would work out if I need to create a new row first before appending a <td>
that my ajax request has created.
Currently I have this code that adds a td to my table,
var interest = "<td>" + msg.name + "</td>";
self.parent().children('table').append(interest);