BarneyJoe Posted December 20, 2006 Share Posted December 20, 2006 I have a table structure :photos : Photo_ID (PK), Title, Orientation etckeywords : Keyword_ID, Keyword, Categoryphotokeywords : Photo_ID, Keyword_IDI originally used hard coded checkboxes that people could use to enter keywords for each photo, but with some help managed to get started with arrays. I actually have it working where the keywords can be updated using an array of checkboxes, using the following code :[code=php:0]<form name="form1" method="POST" action="photoKeywordsEdited.php"><input type='hidden' name='Photo_ID' value='<?php echo $Photo_ID; ?>'><?php require_once('Connections/Photolibrary.php');error_reporting(E_ALL & E_STRICT);$Photo_ID = 1; if (isset($_GET['Photo_ID'])) { $Photo_ID = intval($_GET['Photo_ID']); } mysql_select_db($database_Photolibrary, $Photolibrary); $query_Keyword_Match = sprintf("SELECT * FROM photokeywords WHERE Photo_ID = %s", $Photo_ID); $Keyword_Match = mysql_query($query_Keyword_Match, $Photolibrary) or die(mysql_error()); $photokeywords = array(); while ($row_Keyword_Match = mysql_fetch_assoc($Keyword_Match)) { $photokeywords[] = $row_Keyword_Match['Keyword_ID']; } $totalRows_Keyword_Match = mysql_num_rows($Keyword_Match); $sql = "SELECT * FROM Keywords ORDER BY Keyword_ID";$keywordArray = array(); $query = mysql_query($sql); while ($result=mysql_fetch_assoc($query)) { $keywordArray[$result['Category']][] = $result; } $current_category = ''; foreach ($keywordArray as $categoryData) { if($current_category <> $categoryData[2]['Category']) { //open a new <tr> echo "<tr class=\"categorycell\">\n"; //print the category as a header echo "<td colspan=\"10\">". $categoryData[2]['Category']."</td>\n"; //close the <tr> echo "</tr>\n"; $current_category = $categoryData[2]['Category']; } $row_count = 0;//even row if($row_count%2==0) { $row_type = 'even'; } //odd row else { $row_type = 'odd'; } echo("<tr class=\"".$row_type."\">"); foreach ($categoryData as $keywordData) { echo("<td><input "); if (in_array($keywordData['Keyword_ID'],$photokeywords)) { echo "checked "; } echo('name="ckbox['.$keywordData['Keyword_ID'].']" type="checkbox" class="tickbox2" id="ckbox['.$keywordData['Keyword_ID'].']"></td>'); echo("<td>".$keywordData['Keyword'].'</td>'); if ($counter==4) { echo('</tr><tr>'); $counter = 0; } else { $counter++; } } echo('</tr>'); $row_count++;} ?>[/code]I'm having trouble modifying it for my original Add Keywords page - basically there's a previous page that collects the photo info for the photos table, then the user is directed to the add keywords page (so previously the Photo_ID) was passed through as a hidden field :[code=php:0]<input type='hidden' name='Photo_ID' value='<!--FIELDVALUE:Photo_ID-->'>[/code]As I'm still a bit unfamiliar with the syntax for arrays, can anyone help out with modifying the code above for editing the keywords, to just adding them?Hope that makes sense.Cheers,Iain Link to comment https://forums.phpfreaks.com/topic/31380-help-with-arrays/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.