1

I have a div element inside while (mysql query). So for every entry I want id to increment by 1. If I have "div id="0"" initially, with every new object I want id++. I have no idea how to do it and tried something like this:

<?php //some code
for ($i = 0; $i < $sent+1; $i++)  {
        ?><script>jQuery(".list-row").attr("id", "$i")</script> <?php //some code

.list row is a class of div element. Any ideas how to do it in right way?

1 Answer 1

1

This would do it for you

<?php //some code
for ($i = 0; $i < $sent+1; $i++)  {
    echo '<script>jQuery(".list-row").attr("id", "' . $i . '")</script>';
}

Or maybe this would be better and more readable later

<?php //some code
for ($i = 0; $i < $sent+1; $i++)  {
    echo '<script>jQuery(".list-row").attr("id", "sent_' . $i . '")</script>';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.