We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30884
    • 142 Posts
    Hi there,

    I’ve written a little snippet that retrieves the top positioned image from MaxI-Gallery’s MySQL table and puts it at the top of a ditto summarised item. Now, being well pleased by being able to resolve what I needed to get working on a plain php page, which doesn’t have any [+id+] implemented into it, I then went on to integrate it into ModX 0.95 and ditto 2.02.

    Now I can get the php script to echo the [+id+] but I’m entirely unable to get it to run through the MySQL query!
    I replace the [+id+] with "59" or 59 and it works fine!

    It is as if I’m not able to interrogate the MySQL DB using Ditto’s placeholders or it’s an actual declaration problem that I’m missing!

    <?php
    // --------------------------------------------------------------------
    // Create a top image dynamically from a typical config for maxigallery
    // version 0.1 - 10th April 2007
    // created by TXRX
    // For exclusive use with modx 0.95 and Maxigallery 0.5 (final)
    // ie: not tested in any way, means or differing environments
    // --------------------------------------------------------------------
    
    $sqlusername="sqlusername";
    $sqlserver="sqlserver";
    $sqlpass="sqlpass";
    //$gti_id="59";
    //$gti_page_id=$gti_id;
    $gti_page_id="[+id+]";
    $gti_id=0;
    $gti_row=1;
    $gti_result="";
    $gti_name="";
    $gti_loop=0;
    $gti_numofarticles=6;
    echo "<H2>This is a php script to determine the topmost image and show it on the news pages</h2>";
    echo "<BR>PAGEID:".$gti_page_id."<BR>";
    $gti_location="http://modxserver/cms_tests/assets/galleries/".$gti_page_id;
    $gti_output_tn="";
    $gti_output_full="";
    //mysql_connect($sqlserver, $sqlusername, $sqlpass) or die(mysql_error());
    mysql_select_db("modx") or die(mysql_error());
    $gti_result = mysql_query("SELECT * FROM modx_maxigallery where gal_id = '$gti_page_id' order by pos "); 
    While ($gti_row = mysql_fetch_array($gti_result)and($gti_loop<=$gti_numofarticles)) {;
    $gti_pos[$gti_id]=$gti_row['pos'];
    $gti_name[$gti_id]=$gti_row['filename'];
    $gti_loop++;
    }
    echo "THIS IS Sort of WORKING ::::".$gti_page_id.":::::";
    $gti_output_tn="tn_".$gti_name[0];
    $gti_output_full=$gti_name[0];
    echo "<BR>Image location : ".$gti_location."/";
    echo "<BR>Top image thumbnail : ".$gti_output_tn;
    echo "<BR>Top image large : ".$gti_output_full;
    ?>


    What am I doing wrong? I’m fairly new into ModX but I’m stumped at this one for now!

    I’ve tried the below topic which worked well but I wanted to then utilise Maxi-Gallery’s ease of use etc since the below method needed you to specify a TopStoryImage via a template variable but it I’m able to streamline the frontend editting options to not having to upload images on more than one occasion I’ll be over the moon!
    http://modxcms.com/forums/index.php/topic,13623.0/topicseen.html
      p i x e l p u s h e r e x t r o d i n a i r e
      A x i s A n i m a t i o n . c o m
      • 18397
      • 3,250 Posts
      Replace
      $gti_page_id="[+id+]";
      

      with
      $gti_page_id= isset($id) ? $id : $modx->documentIdentifier;
      

      Then call the snippet in the tpl with &id=`[+id+]`
        • 7455
        • 2,204 Posts
        you could also use maxigalery itself for this

        place this in your ditto call
        [[MaxiGallery? &view_gallery=`[+id+]` &limit=`1` ]]

        this will get the top image from the gallery used on that page
          follow me on twitter: @dimmy01
          • 30884
          • 142 Posts
          Magic! I would have never thought about including the MaxiGallery component into the ditto chunk! Most elegant and useful!

          Also thanks for rectifying the php code into a manner that I’ll be able to use in other areas of passing place holders into our own existing code. I’ve hand coded a shed-load of php for our renderfarm system here and that’s exactly the kind of variable and place holder management I’ll be doing more of in weeks to come!

          Two very helpful replies and both are a big aid in getting these pages bashed into shape! ModX rocks!
          Cheers!

          TXRX
          ps: Soz for the semi-double post, I didn’t realise they were both in the same topic!
            p i x e l p u s h e r e x t r o d i n a i r e
            A x i s A n i m a t i o n . c o m
            • 7923
            • 4,213 Posts
            Quote from: Dimmy at Apr 10, 2007, 02:23 PM

            you could also use maxigalery itself for this

            place this in your ditto call
            [[MaxiGallery? &view_gallery=`[+id+]` &limit=`1` ]]

            this will get the top image from the gallery used on that page
            Yes, or you could also use [[MaxiGallery? &gal_query_ids=`[+id+]` &limit=`1`]], it does just the same.


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 30884
              • 142 Posts
              Again thanks! I’ve got it pegged now. I had to add the following at the very end of the DittoDisplay chunk that I was using which contained the newly added maxigallery snippet call.

              </ul>
              <ul class="thumbs">

              If I didn’t then every image after the 1st in the concurrent article was offset to the right as if they were continued in a row but stepped down on each news item.
                p i x e l p u s h e r e x t r o d i n a i r e
                A x i s A n i m a t i o n . c o m