View Single Post
Old 08-12-2004, 05:37 PM   #1 (permalink)
easilyi
Registered User
 
Join Date: Aug 2004
Location: USA - West Coast
Posts: 9
easilyi is on a distinguished road
Question Problem retrieving subset of records

Hello.
Sorry this is long, but I am stuck. I understand if it is too much for anybody to deal with, but I need to try...
I am trying to display a subset of values (in this case, image names) from my table and a strange thing is happening.

All my image names have a prefix.
For example: Default_Image1.jpg, Default_Image2.jpg, Misc_Image1.jpg, Misc_Image2.jpg.
The prefix represents the gallery name for that group of pictures. So with these pics I have a "Default" gallery and a "Misc" gallery.
I have code to retrieve all pictures in a certain gallery.
The gallery (image prefix) is passed in a variable.
However, when I have multiple galleries (prefixes) and I try to list everything from one, the galleries that come first in the alphabet take precedence over the others.

Here is what I mean:
I have 5 pictures with the prefix "Default" and 5 pictures with the prefix "Extra".
All the the "Default" pictures will display when i pass the "Default" value in my gallery variable, but none of the "Extra" pictures will display if I pass the "Extra" value in my gallery variable.
Now, if I add a picture with the prefix "Booya", only 4 of the "Default" pictures will now display because the 1 "Booya" picture is in there...
whatever gallery has the earliest letter in the alphabet will show all of the picture names.

I am confused.

Here is the code I have:
PHP Code:
<?php

  $dir
="./";
  if (
is_dir($dir))
  {
    
$fd = @opendir($dir);
    if(
$fd)
    {
      while ((
$part = @readdir($fd)) == true)
      {
        if (
$part != "." && $part != "..")
        {
          
$file_array[]=$part;
        }
      }
    }
    
sort($file_array);
    
reset($file_array);
    for(
$i=0;$i<count($file_array);$i++)
    {
      
$npart=$file_array[$i];
      if (!
strstr($npart,".inc.php") && !strstr($npart,"index.php"))
      {
        
$fsize=filesize($npart)/1000;
        if (
is_dir($npart))
        {

        }
        else
        {

          
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
          //  This section of code added to original code in order to find prefix on image names          //
          //  and use only the prefix for the gallery chosen, creating an array of images with the        //
          //  chosen prefix.                                                                              //
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

          
          
$mystring $npart;
          
$findme  $gallery;
              
$count strlen($findme);            // get length of gallery prefix for images
          
$rest substr($mystring0$count); // get string from image name the length of gallery prefix
          
$pos strpos($rest$findme);        // compare string to see if it matches gallery prefix
              
if ($pos === false)                   //if it does not match, do nothing
          
{

          }
          else                                
//if it does match, add image to currentgallery array
          
{
            
$currentgallery[$i] = $mystring;
                  }
                }
          }
        }



    print (
"<small><font color=\"008B45\" face=\"verdana\"><b>Pictures in gallery</b> <i>$gallery</i>:</font></small><br /><br />");

    
$db mysql_connect("localhost""user""pass");
    if (!
$db)
    {
      die(
'Could not connect: ' mysql_error());
    }
    
mysql_select_db("wordpress",$db);
    
$result mysql_query("SELECT * FROM wp_piccaption",$db);
    if (!
$result)
    {
      die(
'Query failed: ' mysql_error());
    }

    for(
$i=0;$i<count($currentgallery);$i++)
    {
      
$result1 mysql_query("SELECT id FROM wp_piccaption WHERE picture = '$currentgallery[$i]'") or die(mysql_error());
      list(
$id) = mysql_fetch_row($result1);
      
$result2 mysql_query("SELECT caption FROM wp_piccaption WHERE picture = '$currentgallery[$i]'") or die(mysql_error());
      list(
$caption) = mysql_fetch_row($result2);

        print (
"<small><a href=\"$currentgallery[$i]\"><img src=\"$currentgallery[$i]\" width=\"50\" height=\"50\"></a>
        $currentgallery[$i]&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"managepicsedit.php?picture=$currentgallery[$i]&caption=$caption&id=$id&gallery=$gallery\"><b>(</b>add/edit caption<b>)</b></a> <a href=\"managepicsedit.php?&deletecap=yes&id=$id&gallery=$gallery\"><b>(</b>delete caption<b>)</b></a></small><br /> "
);
      print (
"<small><b>Caption:</b> $caption</small><br /><br />");

    }


  
mysql_free_result($result);





  }

?>
easilyi is offline   Reply With Quote