1

So I've been struggling with finding a simple and efficient solution for the following problem. The solution I have now works, but since I'm working on this for the sake of learning ...

So, the case:

I have a PHP page which gets loads of persons from a DB, then sorts them and finally puts all persons in a html list. What I'm after is a elegant solution to edit these persons by clicking on them from the list. I've found a jQuery pop-up solution that looks brilliant, but not so easy to use for beginners.

Since there are several persons I need to produce a different pop-up window depending on which person is clicked. The problem is that the jQuery pop-up is based on the html being pre made, which is obviously hard since I don't know which person the user will click.

The best I've come up with so far is sending a GET -variable to the page with the person list, which then checks if there is a valid variable from GET and produces the HTML for the clicked person based on the id/variable. The problem with this is that I have to essentially run the same query twice; once to get all persons and once to get the clicked person. It isn't a big problem, it's more that since I'm new with jQuery I'm wondering if there is a simpler/better solution. I'm not really sure what jQuery can and can't do.

Thanks for any replies.

1
  • I've followed this tutorial: yensdesign.com/2008/09/… The PHP is simple enough, all it does it fetch persons and puts each person in a html list and link/href with an unique ID for each person. Commented Jun 25, 2011 at 11:09

2 Answers 2

1

I'd start by asking why you don't ask the database to sort/ORDER the values before sending them back to your PHP page? It's well-suited for that sort of thing.

You could know which person was clicked if you added the database id to each element and passed that around. Have jQuery add it to the DOM element for each row in the HTML table.

Sign up to request clarification or add additional context in comments.

3 Comments

+1, although I'd suggest keeping the id in a data- attribute in the tr. That may be what you meant, but I get the impression that @KG is pretty new, so I thought I'd explicitly say it.
Whatever - put it someplace. This doesn't seem to be such an intractable problem to me.
Sorry about the confusing first post. I'm using the DB to sort the persons based on their first name, not PHP. ID's on every person I allready got, so that wasn't the problem. The problem was how to manipulate the HTML using PHP-variables with jQuery. The solution was jQuery templates.
0

kinda the standard way would be to pass the persons as JSON, and use the jquery templating system to build the forms. Of course this could be a bit daunting to a beginner, but its not that hard.

1 Comment

Thanks, I'll have a look. I'm starting to lean towards finding another jQuery solution, as the one I has seems a bit restrictive so to speak.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.