Quote Originally Posted by cronsrcs View Post
PHP Code:
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);
echo(
'<table>');

while (
$result=mysql_fetch_assoc($query)) {
    
$keywordArray[$result['Category']][] = $result;
}
$current_category '';
foreach (
$keywordArray as $categoryData)
{
if(
$current_category <> $categoryData['Category'])
            {
                
//open a new <tr>
                
echo "<tr>\n";
                
//print the category as a header
                
echo "<td>"$categoryData['Category']."</td>\n";
                
//close the <tr>
                
echo "</tr>\n";
                
$current_category $categoryData['Category'];
            }       

    echo(
'<tr>');
   
          
        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==3) {
            echo(
'</tr><tr>');
            
$counter 0;
        } else {
            
$counter++;
        }
    
    echo(
'</tr>');
}
print_r($categoryData);
print_r($photokeywords); 
So with the above code you are getting all of the keywords and checkboxes, but just no category headings?
No - with that one it's just showing 7 checkboxes, one on each row.

But with that loop line back in towards the end, it is, ie :

PHP Code:
echo('<tr>'); 
    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==3) { 
            echo(
'</tr><tr>'); 
            
$counter 0
        } else { 
            
$counter++; 
        } 
    } 
    echo(
'</tr>'); 

Can you do some debugging echo's such as after this line:
PHP Code:
foreach ($keywordArray as $categoryData)

try
PHP Code:
echo "Current category is: " .$current_category."<br";
echo 
"Current keywords category is: " .$categoryData['Category']."<br"
Current category is: x 7

So presumably it's counting them (there are 7 categories), but not displaying them. I'll just away and try out what you said above - Category is the third column, ie table keywords : Keyword_ID, Keyword, Category

And a blank with the 'Current keywords category is :' part.

Also, what did the print_r show you?
It seems that there is just a small glitch with the $categoryData['Category'] being echoes etc....I just want to see whether it is getting a var or not...
the prints were as above - the first looking a bit odd, the second looking as you'd expect.