Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed some tips in jquery / json for arrays in photo viewer
    primarykey
    data
    text
    <p>I'm making a photo viewer from scratch and it is working fine, except a few things.</p> <p>The code goes like this:</p> <p>First I have the ID of the current album, and print all the images belonging to the photo. Then, when user click on the photo, this happened:</p> <pre><code> var loaded = []; var albums = []; var album_id = ALBUM ID var cur_pic = 0; var alb_name = ''; $('.photo').click(function(){ var cover_photo = $(this).attr('id').replace("911",""); albums[album_id] = []; $('#photo_preview .pleft').html('&lt;img src="'+cover_photo+'"/&gt;'); $('#photo_preview').show(); $.ajax({ type: 'POST', url: "photo_ajax.php", dataType:'json', data: 'action=get_info' + $('#aid').val().replace("aid",""), success: function(data){ loaded[album_id] = true; albums[album_id] = data; $('#photo_preview .pleft').html('&lt;img src="'+albums[album_id][0]['ImagePath']+'"/&gt;'); // The first photo you click on, will be the first photo to see :) $('#photo_preview').show(); } }) // } }); // Loading images and make them visible in the popup... function loadNextImage(album_id, step){ function loadNextImage(album_id, step){ var next_pic = 0; if(step == 0){ next_pic = 0; }else if(step == 'next'){ next_pic = parseInt(cur_pic, 10)+1; cur_pic = next_pic; if(next_pic &gt;= albums[album_id].length){ next_pic = 0; } }else{ next_pic = parseInt(cur_pic, 10)-1; if(next_pic &lt; 0){ next_pic = albums[album_id].length - 1; } } cur_pic = next_pic; $('#photo_preview .pleft').html('&lt;img src="'+albums[album_id][next_pic]['ImagePath']+'"/&gt;'); } // Loading the next image in the JSON array...: $(".preview_next").click(function(){ loadNextImage(album_id, 'next'); }); // Loading the previous image in the JSON array...: $(".preview_prev").click(function(){ loadNextImage(album_id, 'prev'); }); </code></pre> <p>In photo_ajax.php:</p> <pre><code> $i = 0; $album = array(); foreach( $aImageInfo as $row ){ $album[$i] = array(); $album[$i]['ImageID'] = $row['ImageID']; $album[$i]['ImagePath'] = $row['ImagePath']; $album[$i]['ImageDate'] = $row['ImageDate']; $album[$i]['ImageDescription'] = $row['ImageDescription']; $i++; } echo json_encode($album); </code></pre> <p>This is working, but my questions are now this:</p> <ol> <li><p>var cur_pic = 0; is set to 0, mean it will start to show the first photo in the json array. I need it fixed so I can find witch number in the array the photo I just clicked on is, so it can start to view and count from that spot.</p></li> <li><p>This is now only working inside a album. Say I have a single photo visible on another page. How to fix this so - when I click on it - the photo is visible and I can get the whole json array, and browse through all images belonging to the same album as the photo I have clicked on.</p></li> </ol> <p>Straight example. Say Facebook or Twitter. You have a photo on the wall. Click on it, and you can navigate whole album.</p> <p>How to solve?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload