最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Place variable in div id - Stack Overflow

programmeradmin1浏览0评论

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"


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

Here are two divs with same id.

 <div id="ment">
  </div>
  <div id="ment">
  </div>

I want the id of the two divs to be ment1, and ment2. But automatically.

So I know I will need for example , $i to acpany ment, like ment_$i

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

I hope I am more clear.

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"


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

Here are two divs with same id.

 <div id="ment">
  </div>
  <div id="ment">
  </div>

I want the id of the two divs to be ment1, and ment2. But automatically.

So I know I will need for example , $i to acpany ment, like ment_$i

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

I hope I am more clear.

Share Improve this question edited Dec 28, 2011 at 11:19 user50049 asked Jun 23, 2010 at 16:42 MohamedMohamed 11 silver badge1 bronze badge 2
  • There's actually no question ;-) – Álvaro González Commented Jun 23, 2010 at 16:45
  • 1 Do you need separate IDs? Unless you're finding them by ID, you can handle them separately with jQuery without this... – Nick Craver Commented Jun 23, 2010 at 16:46
Add a ment  | 

4 Answers 4

Reset to default 3

easy, just use

<div id="name_<?php echo $id; ?>"> 
     content 
</div>

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>
}

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>";
    }
?>

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

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

Thanks maate

发布评论

评论列表(0)

  1. 暂无评论