473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to change a specific div in a loop

I'm trying to create a program where the user clicks on the first name in the table and the name hides and the word "delete" appears. My problem is the word "delete" only appears in the first row of first name. I want it to appear in the second row of first name if it was click, I want it to appear in the third row of first name if it was click, and etc.

the div tags and table are within php to connect to my database
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     mysql_connect("******","****","****");
  3.     mysql_select_db("****");
  4.  
  5.     $phonequery = "select * from phonebook";
  6.     $phoneresults = mysql_query( $phonequery );
  7.  
  8.     echo "<div id=\"phonelist\">\n";
  9.     for( $i = 0; $i < mysql_num_rows( $phoneresults ); $i++ )
  10.     {
  11.         $phonerow = mysql_fetch_array( $phoneresults );
  12.         echo "<tr class=\"colhead\">\n";
  13.         echo "<td>".$phonerow["idnum"]."</td>\n";
  14.         echo "<td>". "<div id=\"deletename\">\n". "<a href=\"javascript:void(0);\" class=\"link\" id=\"id_". $phonerow['idnum'] ."\">". $phonerow['firstname']."</a>". "</div>". "<div id=\"appear\" style=\"display:none;\">\n". "</div>". "</td>\n";
  15.         echo "<td>".$phonerow['lastname']."</td>\n";
  16.         echo "<td>".$phonerow['streetaddress']."</td>\n";
  17.         echo "<td>".$phonerow['city']."</td>\n";
  18.         echo "<td>".$phonerow['state']."</td>\n";
  19.         echo "<td>".$phonerow['zip']."</td>\n";
  20.         echo "<td>". "<a href=mailto:".$phonerow['email'].">" .$phonerow['email']."</a>"."</td>\n";
  21.         echo "<td>".$phonerow['dateadded']."</td>\n";
  22.         echo "<td>".$phonerow['friendlevel']."</td>\n";
  23.     }
  24.     echo "</div>";
  25.     ?>
and this is the ajax that will have delete appear and the first name disappear
Expand|Select|Wrap|Line Numbers
  1. $("document").ready( function() {
  2.  
  3.     $(".link").click( function() {
  4.         var del = $(this).attr("id").substring(3);
  5.         $.ajax( {
  6.             url: "deletebook_ajax.php",
  7.             type: "POST",
  8.             data: "del=" + del,
  9.             success: function(msg) {
  10.  
  11.                 $("#appear").html( msg );
  12.                 $("#deletename").hide();
  13.                 $("#appear").show('explode');
  14.             }
  15.         } );
  16.  
  17.     } );
  18.  
  19. } );
Dec 16 '10 #1
1 2433
JKing
1,206 Expert 1GB
You are using an ID for your div. IDs should only occur once per page. Jquery finds the first ID and doesn't search for any others.

Using a class may not work much better either though as it may apply it to all of the rows. A solution might be to append a number on the end of each id to make them unique.
Dec 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: beliavsky | last post by:
In a Python 'for' loop, one can change the value of looping variable, so that for i in range(3): i = i*5 print i is legal code In Fortran 90 and 95, the analogous code
32
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
0
by: temp | last post by:
Hi, I'm not good in regexp. TEXT: <a href="index.php">asasa</a> <a taget href='index.php'>asasas</a> I want to change only "index.php" in all occurance in a link tag.
17
by: Pushkar Pradhan | last post by:
I want to time my matrix multiply code (in MFLOPS). I want to run the code 100,000 times or some other big number. This can be done 2 ways (for and while loops): timer1 = time(NULL); for(n = 0;...
1
by: johnsonholding | last post by:
I have a pop-up flash movie, it works great. Here is the code : <SCRIPT LANGUAGE="JavaScript"> function jumpUp(URL) { window.open(URL, "w"+(new Date()).getTime(),...
7
by: Giacomo | last post by:
I work on a page structured like: <h2> ... </h2> <div ="div1" class="show"> ... </div> <h2> ... </h2> <div id="div2" class="show"> ... </div> <h2> ... </h2> <div id="div3" class="show">...
1
by: emlj001 | last post by:
I have a form that starts at page, http://www.scmeachoraldiv.org/allstate/registration/default.asp My problem is on the page http://www.scmeachoraldiv.org/allstate/registration/part2.asp I...
7
by: UnkleVo | last post by:
Can someone run the code below and tell me why it never reaches 0.06? I am really puzzled..... or just going crazy? Dim i As Double For i = 0.01 To 0.05 Step 0.01 Debug.WriteLine(i) Next...
1
by: dhaneshrs | last post by:
I have a small code that shows inactive and active users from the ms access DB. <%@ Page Language="VB" MasterPageFile="~/MasterPageAdmin.master" Title="Welcome" %> <%@ Import...
4
by: devilsangels287 | last post by:
Hey guys I have a problem with this while loop, its not working properly and I think that I might be typing it wrong but I don't how. please help me! Thanks... Anyways this is a calculator which is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.