Welcome to Geeklog, Anonymous Tuesday, March 19 2024 @ 04:20 am EDT

Geeklog Forums

Help with StaticPage Hack


Status: offline

sharon

Forum User
Junior
Registered: 11/28/04
Posts: 16
Location:Lafayette, Indiana USA
I'm attempting to alter this plugin for use as a profile page. What I've tried to do is to link up a video and a photo, which will be an updated version if this site: http://www.joeyedmonds.com/ (if you click on one of the Artists' names after entering the site).

The problem I'm running into is on the add new/edit page. I have the following code in the gldir/plugins/artistpages/templates/admin/editor.thtml page:

Text Formatted Code
  <tr>
    <td valign="top" align="right">{lang_movie}:</td>
    <td><select name="jap_movie">
    <option value="">Select One</option>
    {movielist}</select></td>
  </tr>
 


It is being processed correctly, except for the movielist. The following code is in the www/admin/plugins/artistpages/index.php page:

Text Formatted Code
$jap_template->set_var('movielist', custom_movielist());
 


Which should use the following code (from the lib_custom.php file):

Text Formatted Code
function custom_movielist()
{
        global $_CONF, $_TABLES;
        $retval = array();

        $sql = "SELECT artistpage.jap_movie, g2_FileSystemEntity.g_pathComponent
        FROM artistpage, g2_FileSystemEntity
        WHERE g2_FileSystemEntity.g_pathComponent LIKE '%.mpg'
        OR g2_FileSystemEntity.g_pathComponent LIKE '%.mov'
        ORDER BY g2_FileSystemEntity.g_pathComponent ASC";

        $result = mysql_query($sql) or die(mysql_error());

        while ($row = mysql_fetch_array($result))
        {
                $japmovie = $row['jap_movie'];
                $movielist = $row['g_pathComponent'];
                if ($japmovie == $movielist) { $select = " selected"; } else { $select = ""; }
                $retval .= "<option value="$movielist"$select>$movielist</option>n";
        }

        return $retval;
}
 


There are 30+ movie files listed in the database, but instead the dropdown is listing each movie 30+ times. I'm not sure how to tweak this, and I wondered if anyone might be able to give me any insight.

Thanks,
Sharon Edmonds :-)
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
without knowing the data in your tables, etc... I cant be sure, but give this a try: edit your select statement to include the "DISTINCT" clause.

eg: $sql = "SELECT DISTINCT artistpage.jap_movie, g2_FileSys...

a good place to start anyway
 Quote

Status: offline

sharon

Forum User
Junior
Registered: 11/28/04
Posts: 16
Location:Lafayette, Indiana USA
no change.

one thing that does work... if i edit the code to only pull from one table....

Text Formatted Code
function custom_photolist2()
{
        global $_CONF, $_TABLES;
        $retval = array();

        $sql = "SELECT DISTINCT g_pathComponent
        FROM g2_FileSystemEntity
        WHERE g_pathComponent LIKE '%.jpg'
        ORDER BY g_pathComponent ASC";
        $result = mysql_query($sql) or die(mysql_error());
        while ($row = mysql_fetch_array($result))
        {
                $photolist = $row['g_pathComponent'];
                $retval .= "<option value=\"$photolist\"$select>$photolist</option>\n";
        }

        return $retval;
}


 


then it will list the items correctly in the dropdown. however, i then can't add a "selected" option to the one that is chosen under the 2nd table. Can someone help me


if there's any other information you might need, please let me know. i'd be happy to post it here.

thanks :-)
sharon


OK, maybe what would help is if i describe my goal...

i want to be able to edit individual "artist" pages (static pages).
there is an option to select a movie file for each individual artist.
when one of these movies is chosen, it is saved to the "artistpage" table under "jap_movie".
i'd like the dropdown on the edit page to display that selected movie within the list.
however, the list is saved from Gallery2 within a table called g2_FileSystemEntity.
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
go back to the two table query, and try this:
instead of ORDER BY, try GROUP BY... you won't need the DISTINCT in this case either and should still return all listings only once even if multiple rows are being returned for the same entry..
 Quote

Status: offline

sharon

Forum User
Junior
Registered: 11/28/04
Posts: 16
Location:Lafayette, Indiana USA
GROUP BY shrank the lists. each file is listed once now. thank you! :-) however, i don't think i have the code correct for the comparison of tables. any clues?

thanks so much for your help
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
Quote by sharon: i don't think i have the code correct for the comparison of tables.
I assume you are asking this because the list is not returning any options as being "selected"... is that the case?

Is there a possibility that your query is returning more than one option that meets the comparison requirements? It is a straight forward comparison otherwise... if one equals another one do this, otherwise do that.

again, without seeing the data or the output I cant suggest to much, but if you aren't getting what you are expecting I suggest that the problem is related to your returned table data and not your comparison operator/syntax.

one other thing to try, change:
Text Formatted Code
$retval .= "<option value=\"$photolist\"$select>$photolist</option>\n";
 
to this
Text Formatted Code
$retval .= "<option value=\"$photolist\"$select >$photolist</option>\n";
 
...notice the extra space added after select variable.. the lack of space before the option's closing bracket seems to return no selected options is some browsers. this was pointed out to me recently in some of my own code.

hope some of that helps
 Quote

Status: offline

sharon

Forum User
Junior
Registered: 11/28/04
Posts: 16
Location:Lafayette, Indiana USA
with or without the space, the result within the page looks like this:

Text Formatted Code
<option value="aanderson.mpg" selected >aanderson.mpg</option>
<option value="abodden.mpg" >abodden.mpg</option>
<option value="bdonohue.mpg" >bdonohue.mpg</option>
<option value="bsantiago.mpg" >bsantiago.mpg</option>
<option value="cjohnson.mpg" >cjohnson.mpg</option>
<option value="csportz.mpg" >csportz.mpg</option>
<option value="dgabriel.mpg" >dgabriel.mpg</option>
<option value="dreed.mpg" >dreed.mpg</option>
<option value="egossling.mpg" >egossling.mpg</option>
<option value="enieves.mpg" >enieves.mpg</option>
<option value="eoshea.mpg" >eoshea.mpg</option>
<option value="fcaliendo.mpg" >fcaliendo.mpg</option>
<option value="gdee.mpg" >gdee.mpg</option>
<option value="gedmonds.mpg" >gedmonds.mpg</option>
<option value="iwitty.mpg" >iwitty.mpg</option>
<option value="jbush.mpg" >jbush.mpg</option>
<option value="jreep.mpg" >jreep.mpg</option>
<option value="lcamp.mpg" >lcamp.mpg</option>
<option value="mcollins.mpg" >mcollins.mpg</option>
<option value="mjr.mpg" >mjr.mpg</option>
<option value="mmooney.mpg" >mmooney.mpg</option>
<option value="rcollier.mpg" >rcollier.mpg</option>
<option value="retta.mpg" >retta.mpg</option>
<option value="rparavonian.mpg" >rparavonian.mpg</option>
<option value="skennedy.mpg" >skennedy.mpg</option>
<option value="tess.mpg" >tess.mpg</option>
<option value="tgabrielson.mpg" >tgabrielson.mpg</option>
<option value="tpescatelli.mpg" >tpescatelli.mpg</option>
<option value="tthirdgill.mpg" >tthirdgill.mpg</option>
<option value="tyoung.mpg" >tyoung.mpg</option>
<option value="vhenley.mpg" >vhenley.mpg</option>
<option value="vmason.mpg" >vmason.mpg</option>
<option value="wfox.mpg" >wfox.mpg</option>
</select>
 


no matter who i select to edit, whether it's aanderson or vmason, they always have aanderson.mpg selected as their movie file.

the problem is in comparing the movie selection in one table to the complete list in another table, when only the id is passed to the edit page.

i'm not sure how to do this, it may just be a matter of tinkering with code for a while. but, if you run across anything, let me know.

thanks a bunch for your help :-)
sharon
 Quote

Status: offline

sharon

Forum User
Junior
Registered: 11/28/04
Posts: 16
Location:Lafayette, Indiana USA
I THINK I'M GETTING CLOSE! :-)

Text Formatted Code
function custom_movielist()
{
        global $_CONF, $_TABLES, $jap_id;
        $retval = '';
        $select = '';

        $sql = "SELECT g_pathComponent
        FROM g2_FileSystemEntity
        WHERE g_pathComponent LIKE '%.mpg'
        OR g_pathComponent LIKE '%.mov'
        GROUP BY g_pathComponent ASC";
        $result = DB_query($sql);
        while ($row = DB_fetchArray($result))
        {
                $movielist = $row['g_pathComponent'];

                $sql2 = "SELECT jap_movie from artistpage WHERE jap_id='$jap_id'";
                $result2 = DB_query($sql);
                while ($row2 = DB_fetchArray($result2))
                {
                        if ($movielist == $row2['jap_movie']) { $select = " selected"; }
                }

                $retval .= "<option value="$movielist"$select>$movielist</option>n";
        }

        return $retval;
}
 


this code isn't working yet, but i think i'm getting close. i think i have to use two SQL queries, but i'm not sure how to combine the two. anyone have any insight?

thanks! Shocked
sharon Smile
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
just a quick fix before i get into it...
Text Formatted Code
                $sql2 = "SELECT jap_movie from artistpage WHERE jap_id='$jap_id'";
                $result2 = DB_query($sql);
 
should say
Text Formatted Code
                $sql2 = "SELECT jap_movie from artistpage WHERE jap_id='$jap_id'";
                $result2 = DB_query($sql2);
 
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
perhaps passing $jap_id to the function, eg, foo($jap_id)...
rather than putting it into your globals--just incase it isn't being defined in any included script or conf file.
Text Formatted Code
function custom_movielist($jap_id)
{
        global $_CONF, $_TABLES;
        $retval = '';

        $sql = "SELECT a.jap_id, g.g_pathComponent
        FROM artistpage a, g2_FileSystemEntity g
        WHERE g.g_pathComponent LIKE '%.mpg'
        OR g.g_pathComponent LIKE '%.mov'
        GROUP BY g.g_pathComponent ASC";

        $result = DB_query($sql);

        while ($row = DB_fetchArray($result))
        {
        if ($row['jap_id'] == $jap_id){
            $select = 'SELECTED';
        } else {
            $select = '';
        }
                $retval .= '<option value="{$row['g_pathComponent']}" $select >$movielist</option>n';
        }

        return $retval;
}

 
give this version a shot assuming you can pass the id to the function. --notice that i went with the two table select... I just like em better. Razz
 Quote

Status: offline

sharon

Forum User
Junior
Registered: 11/28/04
Posts: 16
Location:Lafayette, Indiana USA
i tweaked it a bit:

Text Formatted Code
function custom_movielist()
{
  global $_CONF, $_TABLES, $jap_id;
  $retval = '';
  $sql = "SELECT a.jap_id, g.g_pathComponent
  FROM artistpage a, g2_FileSystemEntity g
  WHERE g.g_pathComponent LIKE '%.mpg'
  OR g.g_pathComponent LIKE '%.mov'
  GROUP BY g.g_pathComponent ASC";

  $result = DB_query($sql);

  while ($row = DB_fetchArray($result))
  {
    $movielist = $row['g_pathComponent'];
    $id = $row['jap_id'];

    if ($id == $jap_id)
    {
      $select = 'selected';
    } else {
      $select = '';
    }
    $retval .= "<option value="$movielist" $select >$movielist</option>\n";
  }
  return $retval;
}

 


with the jap_id up in the function, it's not being passed. as a global, it's being passed. however, the list either shows up as all selected or none selected (i tried messing with what $select equalled... when i make the "else... " $select equal something, it comes up on each option). even when i don't use $id and use the full path ( $row['jap_id'] ) i get the same result. however, if i make the "else" $select equal the jap_id, it will print the correct id, only 33 times but anyway it is passing the jap_id through the code.

i don't know how much that helps, but at i thought i would at least let you know how it's going.

sharon
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
for the sake of debugging, try returning the id's themselves so that you can see what numbers are actually being used.
eg, inside your while put this:
Text Formatted Code
retval .= '<!-- id equals' . $row['jap_id'] . ' and the passed var equals ' . $jap_id . ' -->';
 
hopefully that helps.
 Quote

Status: offline

sharon

Forum User
Junior
Registered: 11/28/04
Posts: 16
Location:Lafayette, Indiana USA
My attempt to simplify the problem:

Text Formatted Code
function custom_photolist1() {
        global $_CONF, $_TABLES, $jap_id;
        $retval = '';

        $path = "/home/jedmonds/www/gallery/albums/headshots/";
        $dir_handle = opendir($path);
        while ($file = readdir($dir_handle)) {
                $fileExt = strtolower(substr($file,-4));
                if (!($fileExt==".jpg")) continue;
                if (strpos($file,'.thumb.')) continue;
                if (strpos($file,'.highlight.')) continue;

                $sql = "SELECT jap_photo1, jap_id FROM artistpage WHERE jap_id='$jap_id'";
                $result = DB_query($sql);
                $A = DB_fetchArray($result);
                if ($A['jap_photo1'] == $file) {
                        $select = " selected";
                } else {
                        $select = "";
                } $retval .= "<option value=\"$file\"$selected>$file</option>\n";
        } closedir($dir_handle);
        return $retval;
}
 


Unfortunately, getting the same results. The jap_id is being passed, but it's not selecting the photo selected in the database (doesn't select anything).
 Quote

Status: offline

sharon

Forum User
Junior
Registered: 11/28/04
Posts: 16
Location:Lafayette, Indiana USA
I've made a little headway....

Text Formatted Code
$path = "/home/jedmonds/www/gallery/albums/movies/";
$dir_handle = @opendir($path) or die("Unable to open $path");
$dirList = array();

while ($file = readdir($dir_handle)) $dirList[] = $file;
sort($dirList);

foreach ($dirList as $file)
  {
    $sql = "SELECT jap_movie, jap_id FROM artistpage WHERE jap_id='$jap_id'";
    $result = DB_query($sql);
    $A = DB_fetchArray($result);

    $fileExt = strtolower(substr($file,-4));
    if (!($fileExt==".mpg" || $fileExt==".mov")) continue;
    if (strpos($file,'.thumb.')) continue;
    if (strpos($file,'.highlight.')) continue;

    if ($A['jap_movie'] == $file) {
      $select = " selected";
    } else {
      $select = "";
    }
    $retval .= "<option value="$file"$selected>$file</option>n";
}
closedir($dir_handle);
return $retval;
 


only, i don't think i have items in the right order. the values (like the jap_id) are being passed elsewhere in the page, but not in the if_else statement where it's supposed to put "selected" next to the jap_movie entry that matches what's in the list.

man i hope that makes sense. if that's not enough info, please let me know.

thanks,
sharon
 Quote

All times are EDT. The time is now 04:20 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content