Forum Moderators: coopster

Message Too Old, No Replies

tags cross referenced with files

         

crackpipe

4:23 am on Sep 30, 2009 (gmt 0)

10+ Year Member



I'm doing a project currently that seems really difficult for a coding noob.
I've found partial solutions with GIS but can't morph them together for a
solution. I'm setting up a tagging system for files in order to have metadata
capability. My provider only has MyISAM so that I have to simulate constraints
and so forth. I used the Toxi system which has three tables:

1. Files (file_id PK, file_name, file_desc, file_pages)
2. Tags (tag_id PK, tag)
3. Tags2Files (tag_id, file_id)

The two PK's autoincrement.
I enter metadata and filenames with a form, but the problem is the coding
required after I POST. Here's the relevant portion of the form:


<tr>
<td><TEXTAREA class="expands" name="item_desc" rows="8" cols="35"></TEXTAREA></td>
<td <input name=[b]"tags"[/b] type="text" size="35" />
<td <input name="item_pages" type="text" size="5" />
<td> <input name="item_name" type="text"></input></td>
</tr>

After POSTing, inserts into 'Files' are no problem. The difficulty is how
how to handle the tags after they POST. Describing the problem is even a
problem. The following is pseudo-code but should explain what I want to do
with the tags and hopefully highlights the problems.

// Check to see if any tags were entered. If no tags were entered, exit
// and reset the form for the next file entry. If tags exist, explode tags
// into array.


if !($_POST('tags')) then [code to exit and reset form]
else $taglist=explode (" ", ($_POST('tags'));


// Check each $taglist array field to see if the tag already exists in 'Tags'
// If tag does not yet exist in 'Tags', insert into 'Tags' and retrieve
// its Tags.tag_id. If tag exists in 'Tags', get its Tags.tag_id, but make
// no insertion


for each [] in $tagarray {
select row "$tagarray[]" from 'Tags.tag';
if select=null { INSERT into Tags (tag) VALUE ('$tagarray[]');
$newtagid=mysql_insert_id();
}
else $newtagid=(SELECT 'Tags.tag_id' from selected row above);


// Insert the tag_id and file_id together in 'Tags2Files'

INSERT into Tags2Files (tag_id, file_id) VALUE ('$newtagid', '$newfileid');
}

Hopefully this makes some sense, and I greatly appreciate any assistance.

crackpipe

4:31 am on Sep 30, 2009 (gmt 0)

10+ Year Member



This reply is just an EDIT for the post above. A corrected version of the form in the post above follows, with the appropriate variable names:


<tr>
<td><TEXTAREA class="expands" name="file_desc" rows="8" cols="35"></TEXTAREA></td>
<td <input name=[b]"tags"[/b] type="text" size="35" />
<td <input name="file_pages" type="text" size="5" />
<td> <input name="file_name" type="text"></input></td>
</tr>

Sorry about the confusion.