element IDs inside loops?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cone13cone
Forum Newbie
Posts: 24
Joined: Fri Mar 20, 2009 8:32 pm

element IDs inside loops?

Post by cone13cone »

I'm having trouble with this bit of code:

Code: Select all

 
while($rows=mysql_fetch_array($result)){
if(is_odd($i)){
echo "<tr class = 'odd'>";
} else {
echo " <tr>";
}
echo"<td>".$rows['JID']."</td>
     <td>".$rows['CID']."</td>
     <td>".$rows['fdate']."</td>
     <td class = 'bunked'><ul><li>".$rows['pname']."</li>
                              <li class = 'bunked'>".$rows['zname']."</li></ul></td>
     <td class = 'bunked'><ul><li>".$rows['name']."</li>
                              <li class = 'bunked'>".$rows['address']."</li></ul></td>
     <td class = 'bunked'><ul><li>".formatPhone($rows['home'])."</li>
                              <li class = 'bunked'>".formatPhone($rows['cell'])."</li></ul></td>
     <td>".$rows['summary']."</td>
     </tr>
     <tr class='space'><td id = 'space".$i."' colspan = '7'></td></tr>";
      
$i++;
}
 
The problem lies with this td id = 'space".$i."' which im trying to set a unique ID for each while pass and them be able to call a specific ID via javascript. I am to utilize the first instance of the id "space" but thats it. any ideas on what im doing wrong?
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: element IDs inside loops?

Post by divito »

Shouldn't it be:

Code: Select all

<tr class='space'><td id='space'".$i." colspan='7'></td></tr>";
Although, can you have ids and classes with the same name? I'm a nubface.
mischievous
Forum Commoner
Posts: 71
Joined: Sun Apr 19, 2009 8:59 pm

Re: element IDs inside loops?

Post by mischievous »

Code: Select all

 
$i=1;
while($rows=mysql_fetch_array($result)){
    
//display if row is even or odd
if(is_odd($i)){echo "<tr class= 'odd'>";} else {echo "<tr>";}
 
//display rest of table row
echo"<td>".$rows['JID']."</td>
    <td>".$rows['CID']."</td>
    <td>".$rows['fdate']."</td>
    <td class='bunked'>
        <ul>
            <li>".$rows['pname']."</li>
            <li class='bunked'>".$rows['zname']."</li>
        </ul>
    </td>
    <td class='bunked'>
        <ul>
            <li>".$rows['name']."</li>
            <li class='bunked'>".$rows['address']."</li>
        </ul>
    </td>
    <td class='bunked'>
        <ul>
            <li>".formatPhone($rows['home'])."</li>
            <li class='bunked'>".formatPhone($rows['cell'])."</li>
        </ul>
    </td>
    <td>".$rows['summary']."</td>
    </tr>
    <tr class='space'>
        <td id='space".$i."' colspan='7'></td>
    </tr>";
//increment counter
$i++;
}
 
That should do it... :twisted:
mischievous
Forum Commoner
Posts: 71
Joined: Sun Apr 19, 2009 8:59 pm

Re: element IDs inside loops?

Post by mischievous »

True... did a quick type out of it and wasnt thinking... glad you were on the ball! :wink:
Just set $i to 2
Post Reply