Jump to content

Recommended Posts

Here's my code

echo "<tr bgcolor='$fillcolor'>
                          <td>$row[mem_username]</td>
                          <td width='20'><input name='$row[member_id]name' type='text' class='text_boxes' tabindex='$tab' size='20' maxlength='100' /></td>                          
                          <td align='center'><input type='checkbox' tabindex='$tab+1' name='$row[member_id]activated' $act></td>
                          <td align='center'><input type='checkbox' tabindex='$tab+2' name='$row[member_id]priv_admin' $admin></td>
                          <td align='center'><input type='checkbox' tabindex='$tab+3' name='$row[member_id]priv_file' $file></td>
                          <td align='center'><input type='checkbox' tabindex='$tab+4' name='$row[member_id]priv_guest' $guest></td>
                          <td align='center'><input type='checkbox' tabindex='$tab+5' name='$row[member_id]rights_news' $news></td>
                          <td align='center'><input name='delete' type='submit' class='button' tabindex='$tab+6' value='DELETE' /> | <input name='save' type='submit' class='button' tabindex='3' value='SAVE' /></td>
                          </tr>";
                    $tab=$tab+7;

This code is inside a while loop, so instead of existing the echo each time to increase the variable, how can I do this on-the-fly within the echo?

echo $tab++

 

will not work in an echo.

 

$x = 1;
echo "blah" . $x++ . "moreblah"; // will inc $x but will not echo result
echo "blah" . ($x+1) . "moreblah"; // echoes 2 but does not inc $x
echo "blah" . ($x=$x+1) . "moreblah"; // incs and echoes 2

echo comes before ++ in order of operation, so the var will be echoed first, then incremented.  Try your own code. It only echoes 3 vars, because on your first $i++, $i doesn't exist, so it echoes nothing. 

 

<?php
$x = 1;
echo $x++; // output: 1
echo $x; // output: 2
?>

 

Output: 12

But it still would work for the original code, where $tab was declared before the loop.

And there's also preincrementing available.

 

echo ++$i." ".++$i." ".++$i." ".++$i;

 

You suggested $tab++ this will not work because OP wants the next incremented value to echo. $tab++ will have it "lag behind".  And yes, ++$i will work, but that's not what you suggested, now is it?

Look at the code OP posted. We can safely assume, that $tab is declared as an integer number somewhere before it, because otherwise

tabindex='$tab'

would echo

tabindex=''

and I doubt it was OP's goal. What's more, $tab has a value of first tabindex to be used in this section of code. So in this case postincrementation would work perfectly well, now wouldn't it?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.