views:

69

answers:

5

I want to use an incremental div id, so that all my id are unique, therefore I can use jquery effects to modify them independently.

I hope my question makes sense. If i need to elaborate please let me know.

div id ="name_$id"

A: 

Sounds like you already have it.

As a loop:

<?php
    for($i = 0; $i < $some_max_value; $i++){
        echo "<div id=\"name_$id\">stuff</div>";
    }
?>
Brendan Long
A: 

something like this? You're question isn't very clear, but you can use a loop and give unique ids like so:

for($i=0;$i < 10;$i++;) {
    echo "<div id='idhere_$i'>";
    echo "stuff in the div";
    echo "</div>
}
GSto
Oh sorry, I am using Zen Cart, and it generates several divs, who all have the same div id.If i want to hide all the divs, it only hides the first div. Any other div with the same div is still displayed.So if I have to generate several divs with a different id each.Anyways Thanks, GSto. I think your example is what I am going to need.<div id ="idname_.'$variablename')So some sort of prefix followed by a variable name.
Mohamed
yes, or you could change is from an id to a class. no two elements should ever have the same id. Zen Cart isn't the best product when it comes to e-commerce, so it wouldn't be suprised to here of it doing something like that.
GSto
Well, I think all ecommerce packages are very similar. Where one has an advantage to others it would be at the expense of another feature. But yh is it possible that I cud send you my php file? Where I am trying to show/hide divs. It is the file I test with, so that I understand how scripts work and stuf?
Mohamed
No worries, I found a great tutorial on http://www.adipalaz.com/experiments/jquery/expand.htmlIt was the expand/collapse all that i was after.Thanks maate
Mohamed
+1  A: 

easy, just use

<div id="name_<?php echo $id; ?>"> 
     content 
</div>
jpabluz
Thanks jpabluz. Im gonna play with that now.
Mohamed
A: 

Ok maybe I have to be more clear about my question.

Here are two divs with same id.

 <div id="comment">
  </div>
  <div id="comment">
  </div>

I want the id of the two divs to be comment1, and comment2. But automatically.

So I know I will need for example , $i to accompany comment, like comment_$i

I also know that I will have to increment i++ after each div displayed.

I hope I am more clear.

Mohamed
Please do not provide additional information to your question as answer. SO does not work like a Forum. Use the Edit Question link instead.
Gordon
On a sidenote, two DIVs with the same ID may not exist. It's invalid.
Gordon
A: 

No worries, I found a great tutorial on http://www.adipalaz.com/experiments/jquery/expand.html

It was the expand/collapse all that i was after.

Thanks maate

Mohamed