Disclaimer: this is for an assignment. I am not asking for explicit code. I only want enough information so that I may understand the task at hand and learn the associative parts.
I'm working on an assignment that requires me to accept a name and a picture through a form, put both into a database, then display all the names in the database below the form. The names are supposed to be clickable, and on click, display their respective picture in a div below the names.
I have gotten far enough to store the names and images in the database (I know, storing images in a database is bad, but it's part of the assignment.) The last part I have to finish is the linking and image display.
I have decided to give each name its own div, in a fairly reckless fashion:
for ($i = 0; $i < $nrows; $i++) {
$name = htmlspecialchars(mysql_result($results, $i, "first_name")). " " .htmlspecialchars(mysql_result($results, $i, "last_name"));
echo "<div id='".$name."'>";
echo $name;
echo "</div>";
}
So this works like a table, except each div has a unique ID (the name of the person, though I could change this to a numeric ID.) I figure it's fairly elementary to give an on-click function to each div, based on its unique id, but I'm not certain if I should do that within the bounds of the loop or outside...
Furthermore, I'm not exactly sure how to set up that on-click function to select the image of the specific name. Each image is stored as a LONGBLOB and as such needs to be encoded into an image form before being displayed. I know that base64_encode should work for this, but I can't seem to put it together in my head.
Please let me know if you need more of my code - I'll be happy to supply it. Otherwise, thank you for your time and your assistance.
Edit #1 (11:44am, 2/18/13):
$('#$name').click(function() {
$("#image-div").html("<img src='data:image/jpeg;base64,'.base64_encode(mysql_result($results, $i, 'photo')).'>");
});