Hi guys. I'm trying to validate some code, but getting ID already defined errors...which I 'm expecting as the code loops through a record set and re-uses the DIV id.

The question is how would you get round this? I thought about adding a simple variable +1 to the ID name as it loops, but it seems a bit of a fudge really...

Any suggestions? Thx in advance

<?
				while($row = mysql_fetch_array($result)){			
				
					if($row['depth']<1){
						echo "<h1>Buy ".$row['name']."</h1>";
						echo "<div id=\"buy_detail_sub\">";
						
						if(check_language_desc(stripslashes($row[$desc_lang]))){
							// we do have a description for this language...
							echo stripslashes($row[$desc_lang]);
						} else {
							//we don't have a description, so default to english
							echo stripslashes($row['description']);
						}
						
						echo "</div>";						

					} else {
						
						
						if($toggle){
							echo "<div id=\"buy_detail_sub_header_l\">
							 <a href=\"/buy/".$row['category_url']."/\">$row[0]</a>
							</div>";
							$toggle = 0;
						} else {
							echo "<div id=\"buy_detail_sub_header_r\">
							 <a href=\"/buy/".$row['category_url']."/\">$row[0]</a>
							</div>";
							$toggle = 1;
						}
					
					
					}
				}
		?>

Recommended Answers

All 2 Replies

Do you really need IDs? Usually if you are going to group some elements together for some reason, use the "class" attribute instead of IDs.

Yes, I think that would make the most logical sense.

As the class can control the style repetition, and get rid of the issues with the repeating Div entirely.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.