Jump to content

keywords and forms....


therob1

Recommended Posts

Hi, im new to the forum and also to php, ive had a look through the tutorials and various threads but cant seem to find what im after.

 

im created a simply image gallery that auto creates my thumbnails and allows for editing the image with gdlibrary etc all very good here.

 

I recently decided to start work on the image keyword tagging so i could carry out searches etc on my very large image collection. i created the usual 3 table setup as im going to have a many to many relationship, so i have my "images" table,  "keywords" table and a "img_key" table to link them together. As i understand it this would seem like the best setup for what i want to achieve, if not would someone be able to advise what i should be doing to get better results.

 

Ok so the main problem i have now is that i want to show a series of check boxes underneath each image that gets selected so i can start tagging the uploaded images, to do this i used "select * from keywords" which gave me all keywords available - which is what i want......

 

However, i now want to somehow add to this so that once the page loads it knows which keywords have already been selected and ticks the relevant boxes automatically, as I have an sql update statement linked to the tickboxes/submit button i want to ensure i dont forget to re-tick any boxes

 

So in a nutshell i need help with displaying all keywords each as a tickbox and if they have already been linked in my 'img_key' link table then they will tick the related tick box automatically , depending on what i need to change im guessing i may need to revise my updating of mysql ?

 

ive been struggling with this silly problem now for a few weeks so im desperate for some assistance  :'(

Link to comment
Share on other sites

Answer #1: Yes, you're doing [the database] right so far. In most cases that's what you should do so keep at it.

Side note #1: When the code adds the tags to an image, does it delete any existing tags first?

 

Answer #2:

You're probably sorting the tags by name, right? Or sorting by something. Run a query that pulls the existing tags for an image in that same sort order.

Now, at the point where you start spitting out checkboxes you have two "lists": one of possible tags, one of applied tags. Run through both loops at the same time. Since they're sorted you can use a very efficient algorithm instead of having to use in_array() or run a specific SQL query for each tag.

$current = mysql_query("whatever SQL query for all the current tags ORDER BY the same 'something' as above");
$possible = mysql_query("whatever SQL query for all the possible tags ORDER BY something");

$c = mysql_fetch_array($current);
while ($p = mysql_fetch_array($possible)) {
$checked = false;
if ($c && $p["sort field"] == $c["sort field"]) {
	$checked = true; // they match
	$c = mysql_fetch_array($current); // next tag in the list
}

// show the tag
// $checked == if the checkbox should be checked (ie, the tag is in use)
}

The "sort field" needs to be 100% unique: the tag name probably qualifies.

Link to comment
Share on other sites

many many thanks for this Requinix, i can now see where i was going wrong as i was trying to stick both queries in a while loop to get the values.

 

I had previously assumed and disregarded actioning the one array outside of a loop as it would just keep returning one value and not moving onto the next value in the array - guess i need to revisit arrays in more detail!

 

:D :D :D

Link to comment
Share on other sites

having had a chance to think about the solution above i now realise ive missed something so obvious and simple - the ability to group certain tags. would i be right in thinking i need to somehow change my check boxes to arrays ? how hard would it be to do this?

 

im also left wondering if this element of the project is best covered by using php or would it just look to clunky and javascript would make things work/look better ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.