How to do the multiple items with the same id?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kiko
Forum Newbie
Posts: 23
Joined: Fri Sep 07, 2007 6:42 am

How to do the multiple items with the same id?

Post by kiko »

Hi all,
I'm having the problem while using the edit-in-place scripts (http://24ways.org/2005/edit-in-place-with-ajax) from internet. It's ok when i just used for one text id, but after i added a while loop because of multiple items and it become only the 1st text id content works. So below here i post a piece of my code, hope any here can help on this. How to do the multiple items with the same id? Please help. Thank you very much.

Code: Select all

 
while($disp=mysql_fetch_array($disp_de))
{           
echo '<tr><td>';
$dis= $disp['pp_desc'];
echo "<p id=\"desc\">".$dis."</p>";
echo '</td></tr>';
}
 
Last edited by kiko on Mon Mar 03, 2008 1:59 pm, edited 1 time in total.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: How to do the multiple items with the same id?

Post by Jonah Bron »

IDs are meant to be a one-time occurance.
kiko
Forum Newbie
Posts: 23
Joined: Fri Sep 07, 2007 6:42 am

Re: How to do the multiple items with the same id?

Post by kiko »

hi PHPyoungster,
thanks,
PHPyoungster wrote:IDs are meant to be a one-time occurance.
then how to make it able to occur for everytime in the while loop? Can it be done? this is because i had tried the code that inside the comments of the page above it changed the scripts inside function init(), and it didn't work for my case.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: How to do the multiple items with the same id?

Post by Chris Corbyn »

I don't really understand what it is you're trying to do, but just make the IDs different so they are unique.

Code: Select all

$i = 0;
while($disp=mysql_fetch_array($disp_de))
{          
  echo '<tr><td>';
  $dis= $disp['pp_desc'];
  echo "<p id=\"desc_$i\">".$dis."</p>";
  echo '</td></tr>';
}
kiko
Forum Newbie
Posts: 23
Joined: Fri Sep 07, 2007 6:42 am

Re: How to do the multiple items with the same id?

Post by kiko »

hi Chris Corbyn,
thanks for help. But it can't work. Should I modify anything inside the js file?
here is i tried to modify the function inside the editinplace.js, which i refer to the comments that below the page as i stated before in this post. But it can't work to me also.

Code: Select all

function init(){
 
var max = 50;
 
for (i = 1; i < max; i++){
 
makeEditable(‘item_’+i);}
 
}
Any expert please guide, thanks. :?
kiko
Forum Newbie
Posts: 23
Joined: Fri Sep 07, 2007 6:42 am

Re: How to do the multiple items with the same id?

Post by kiko »

Anyone? :(
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: How to do the multiple items with the same id?

Post by pickle »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not receive a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
kiko
Forum Newbie
Posts: 23
Joined: Fri Sep 07, 2007 6:42 am

Re: How to do the multiple items with the same id?

Post by kiko »

Hi, does any know how to slove this problem? :? Thanks.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: How to do the multiple items with the same id?

Post by Zoxive »

kiko wrote:Hi, does any know how to slove this problem? :? Thanks.
As everyone else has already stated, it is not possible to "target" multiple items with the same ID. The dom only will recognize one, this is the whole purpose of IDS, to be unique.

Classes are made to not be unique. Have a look at them, if you are using a JavaScript framework it is pretty simple to select all of the same classes.

Code: Select all

${'.classname')
kiko
Forum Newbie
Posts: 23
Joined: Fri Sep 07, 2007 6:42 am

Re: How to do the multiple items with the same id?

Post by kiko »

thanks, Zoxive. Actually I had just solved this problem but now it will appear the error on page icon at the bottom left of my page. You know about this Zoxive? I modified as the below code. Thank you.

Code: Select all

 
 while($disp=mysql_fetch_array($disp_de))
{
    echo '<tr><td>';
    $dis= $disp['pp_photo_desc'];
[b]    echo '<p id="desc'.$a.'">'.$dis."</p>";[/b]
    echo '</td></tr>';
    $a++;
}
 
and in the function init()

Code: Select all

 
function init(){
var max=50;
for(i=0; i<max ;i++){
[b]makeEditable('desc'+i);[/b]      //if I put semicolon in the end of i, then I'll not get the error but I'll not get what I need.
}
}
 
Post Reply