title: Jquery PHP/Mysql image manager
body: <p>I'm working on a CMS at the moment and have been looking for a suitable Jquery/Php image manager but can't find anything that really suits my needs. So I've decided to have a go at building the image manager myself. The bad news is I'm not particularly up to speed with my Jquery...actually I know very little. But I'm working my way through it.</p>
  
  <p>The end result will display an unordered list of images.</p>
  
  <pre><code>&lt;ul&gt;
  &lt;li&gt;&lt;a href="#" id="imgid"&gt;&lt;img src="imgsrc" /&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;ul&gt;
  </code></pre>
  
  <p>When the user clicks on an image the ID of that image is sent to a Jquery function and stored in an array. The image is highlighted with a border added by addclass(). If the user clicks on a subsequent image that image ID is also sent to the Jquery array and the second image is also highlighted.</p>
  
  <p>This continues until the user doesnt click on any further images. Naturally if the user clicks on an image that is already contained in the Jquery array then it is removed and the highlighted effect is also removed.</p>
  
  <p>Following this the user will select a catalogue item from a select menu that sits below the image list. The ID of that item is also passed to Jquery.</p>
  
  <p>When the user clicks submit the Jquery array and select ID are sent to a PHP script that updates a MySQL table, linking the image ID to the catalogue item ID.</p>
  
  <p>Where I'm up to currently is...I have a lovely unordered list of images.</p>
  
  <p>My questions are</p>
  
  <ol>
  <li>How do I send the image id to the jquery array, and subsequently remove that id if the same image is clicked again</li>
  <li>How do I send the Jquery array to the PHP script to be executed</li>
  </ol>
  
  <p>I have got some of this working in code snippets at the moment, but as Jquery is far from my forte Im just rinsing and repeating until I get the code right. Any help would be great.</p>
  
  <p>Mark</p>
  
  <p>So Ive been trying this code snippet, but I think i could be written better.</p>
  
  <pre><code>$(document).ready(function() {
      $("img").click(function(event) {
          var test = (event.target.id);
          if($('img[id=' + test + ']').is('.error'))
              $('img[id=' + test + ']').removeClass("error");
          else
              $('img[id=' + test + ']').addClass("error");
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Surely there's another way to target the img id without having to use 'img[id=' + test + ']'</p>
  
  <p>Mark</p>
  
  <p>Edited again</p>
  
  <pre><code>$(document).ready(function() {
      $("img").click(function(event) {
          var img_id = (event.target.id);
          var imgArray = new Array();
          if($('img[id=' + img_id + ']').is('.selected')) {
              $('img[id=' + img_id + ']').removeClass("selected");
              $('span[id=check_' + img_id + ']').removeClass("check-ok");
              removeArray();
              }
          else {
              $('img[id=' + img_id + ']').addClass("selected");
              $('span[id=check_' + img_id + ']').addClass("check-ok");
              addArray();
              }
          function removeArray() { 
              alert('Removing from the array');
              }
          function addArray() {
              alert('Adding into the array');
              }
          });
      });
  </code></pre>
  
  <p>Trying to figure out how to insert the images into the array, and then remove them from the array.</p>