Hi. I'm relatively fresh with PHP, but I'm learning as I write a CMS for work.

I am using a mysql_fetch_array loop to fetch individual rows from the MySQL database. Currently, I'm working on a window for editing entries, and for that I use this tutorial for a "popup".

I'm using a column called ID as the auto-incrementing primary key, and I want to send this to the edit popup for the individual entries with a button for each row.

I have a <fieldset> for the code on the edit popup, and it's outside the loop. Inside the fieldset are the forms I'm going to use.

Anyhow, what has been boggling me for some hours is how to do this. I don't know any way to pass a variable from a single row inside the loop, to this popup. I've tried $_GET, but then I had to reload the page. If I simply call the popup inside the loop, it'll only show the variable of the first row because it doesn't send individual variables that way.

The edit page is called with:

echo "<a href='#' class='signin'>Edit entry</a>";

I'm sorry if this is badly written, but I have no idea how to phrase it otherwise.

    if i understand the question ...

    put the id in the href id field

    echo "<a href='#' id='"$id"' class='signin'>Edit entry</a>"; 

    in jquery you can retrieve it with

    var link_id= $(this).attr("id");
      dagon;10967765 wrote:

      if i understand the question ...

      put the id in the href id field

      echo "<a href='#' id='"$id"' class='signin'>Edit entry</a>"; 

      in jquery you can retrieve it with

      var link_id= $(this).attr("id");

      Thanks, I still don't really know jquery, or javascript in general, but this seems to return a null value for me. Passing the variable through the url is a good option, though. I've tried using onclick before but I didn't quite know how to do that.

      I might have misunderstood completely, but this is what I tried to test it:

      echo "<fieldset id='signin_menu'>
      <script type='text/javascript'>
      var link_id= $(this).attr('id');
      document.write ($link_id);
      document.write(link_id);
      </script>";
      echo $link_id"
      </fieldset>";

      There's also a javascript part for the signin_menu:

      <script type="text/javascript">
              $(document).ready(function() {
      
              $(".signin").click(function(e) {          
      			e.preventDefault();
                  $("fieldset#signin_menu").toggle();
      			$(".signin").toggleClass("menu-open");
              });
      
      		$("fieldset#signin_menu").mouseup(function() {
      			return false
      		});
      		$(document).mouseup(function(e) {
      			if($(e.target).parent("a.signin").length==0) {
      				$(".signin").removeClass("menu-open");
      				$("fieldset#signin_menu").hide();
      			}
      		});			
      
          });
      </script>

        my bit of jquery needs to be inside your click(function(e ...

        although I'm not suer what your using the id for in this case.

        do you have this on the web somewhere?

          dagon;10967767 wrote:

          my bit of jquery needs to be inside your click(function(e ...

          although I'm not suer what your using the id for in this case.

          do you have this on the web somewhere?

          Oh, sorry but I'm new to javascript so it would be nice with an example. Tried this..

          echo "<a href='#' id='".$id."' onClick='var link_id= $(this).attr('id');' class='signin'>Edit entry</a>"; 

          and also putting it in a function and calling it. if it's correct, then I'm still not sure how to read the variable. Maybe this should have been in the newbie section..

          sorry, it's not online right now, but this outline demonstrates a bit: http://i.imgur.com/1fFG3.png

          Basically, when you press Edit entry, you get this popup with forms for editing purposes for that specific row. There's nothing in it yet, but as soon as I figure out how to send the id it'll be a breeze to do the rest.

            Write a Reply...