Here is the PHP code that generates the entire table, plus the empty table
row.



<table width="555px" border="0" id="groups">
        <?php
        $query =     "SELECT * FROM users
                     JOIN groups ON users.userID = groups.userID
                    WHERE users.username = '" . $_SESSION['MM_Username'] .
"'
                    ORDER BY id ASC";

        $result = mysql_query($query);
          while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ ?>
               <tr id="group<?=$row['id']?>">
               <td>
                   <span>
                       <a href="javascript:;" alt="Modify" title="Modify"
class="editgroup" onclick="editGroup(<?=$row['id']?>)"><img
src="images/icons/pencil.png" /></a>
                       <a href="javascript:;" alt="Remove" title="Remove"
class="deletegroup" onclick="deleteGroup(<?=$row['id']?>)"><img
src="images/icons/cross.png" /></a>
                       <span id="groupid<?=$row['id']?>">
                           <span class="gname"><?=$row['groupname']?></span>
                   </span>
               </td>
               </tr>
               <?php } ?>

       <tr></tr>
     </table>



Is there a better method I could be using so that I won't be spitting out
invalid code?

On Mon, Jul 13, 2009 at 6:51 PM, James <james.gp....@gmail.com> wrote:

>
> I don't see anywhere in the code where you're setting an ID to the
> <tr>. And if you're cloning an existing <tr> that has an ID, that may
> cause issues because IDs are suppose to be unique on a page.
> Is there any reason you're cloning an existing <tr></tr> instead of
> just appending it in with all the other <td> content?
> Having <tr></tr> by itself is not valid because it has no <td> in it,
> and might cause display issues.
>
> On Jul 13, 12:34 pm, Nate <nathanle...@gmail.com> wrote:
> > I have a table that is dynamically populated by PHP and MySQL.
> >
> > At the bottom, I've created an empty table row: <tr></tr>
> >
> > I have a jQuery function that posts data to a PHP file.  When the PHP
> > file returns "true", I want it to clone that emtpy table row, and then
> > manipulate it by giving the table row an ID.
> >
> > For example, that empty table row would clone (creating an additional
> > empty table row for future use), and then look like <tr
> > id="group34"><td>data here</td></tr>
> >
> > Here's the jQuery I have now, however, it creates the <tr> with no ID:
> >
> > $.post("addgroup.php", { groupname:f.groupname },
> >     function(data){
> >     $("#groups tr:last")
> >     .clone(true)
> >     .insertAfter("#groups tr:last")
> >     .fadeIn("fast")
> >     .html('<td><span>'+
> >     '<a href="javascript:;" alt="Modify" title="Modify"
> > class="editgroup" onclick="editGroup(' + data.id + ');">'+
> >     '<img src="images/icons/pencil.png" /></a>'+
> >     '<a href="javascript:;" alt="Remove" title="Remove"
> > class="deletegroup" onclick="deleteGroup('+data.id+');">'+
> >     '<img src="images/icons/cross.png" /></a></span>'+
> >     '<span id="groupid' + data.id + '"><span class="gname">' +
> > data.groupname + '</span></span></td>')
> >
> > }, 'json');
> >
> >
> >
>

Reply via email to