AARoads Forum

Please login or register.

Login with username, password and session length

Author Topic: AARoads PHP Help  (Read 938 times)

Alex

  • Webmaster
  • *
  • *
  • Offline Offline

  • Posts: 4808
  • Location: Tampa, FL
  • Last Login: October 18, 2019, 06:40:55 AM
    • AARoads
AARoads PHP Help
« on: October 06, 2017, 08:31:19 AM »

Jake wrote the original guide.php script that generates most of the pages on the web site. We are trying to make some changes/upgrades to it.

When it finds succeeding photo entries in the database with the same caption field, it groups them together. We cannot parse where it gets the extra filenames for the entries with the same captions. Was wondering if any of our more code-savvy members could take a look and figure it out.

Code: [Select]
$numentries = mysql_num_rows($photodata);

for($i = 0, $k = 0; $i < $numentries; $i++) {

    $filename = mysql_result($photodata, $i, "filename");
    $caption = mysql_result($photodata, $i, "caption");
    $suborder = mysql_result($photodata, $i, "suborder");
    $sepstyle = mysql_result($photodata, $i, "sepstyle");

    if(!($sepstyle & 1)) {
   
      echo "\n" . '<table class="guidecontent">' . "\n" . '<tr>' . "\n";
    }

    if(strlen($filename) > 0) {
 
      # picture entry

        $longentry = 1;
        $photocredit = '';
        $pdates = array();

        for($j = $i; $j < $numentries; $j++) {

            if($caption != mysql_result($photodata, $j, "caption")) { break; }

$filename = mysql_result($photodata, $j, "filename");
$datetaken = mysql_result($photodata, $j, "datetaken");

            if(strlen($datetaken) > 0) {

switch($j - $i) {

case 0 : {$photocredit .= 'First'; break; }
case 1 : {$photocredit .= 'Second'; break; }
case 2 : {$photocredit .= 'Third'; break; }
case 3 : {$photocredit .= 'Fourth'; break; }
case 4 : {$photocredit .= 'Fifth'; break; }
case 5 : {$photocredit .= 'Sixth'; break; }
}

$photocredit .= ' photo taken ';

                $pdate = date("m/d/y", strtotime($datetaken)) . '. ';
                $photocredit .= $pdate;
                $cphoto = 'Photos taken ' . $pdate;

                array_push($pdates, $pdate);
               
            }

            for($m = 0; $m < count($mainfolderarray); $m++) {

              $path =  $mainfolderarray[$m] . '/'. $filename;
              $thbpath = $mainfolderarray[$m] . '/thb/'. $filename;

              if(file_exists($path)) { break; }
            }

            echo '<td><a href="' . $path . '" class="fancybox-buttons" data-fancybox-group="button" title="' . strip_tags($caption . ' Photo taken ' . $pdate, '<p>') . '"><img src="' . $thbpath . '" title=" "></a>';

            # delete this if you don't want suborder displayed
            #         echo $suborder;

            echo '</td>' . "\n";

            if(($j - $i) == 2) {

                $longentry = 3;
            }
            if((($j - $i) % 4) == 3) {

              $longentry = 4;
              echo '</tr>' . "\n" . '<tr>';
            }
        } # for $j

        if(($j - $i) == 1) {
            $photocredit = str_replace("First photo", "Photo", $photocredit);
        }
        else {
            $photocredit = (sizeof(array_unique($pdates)) == 1) ? $cphoto : str_replace("First photo", "Photo", $photocredit);
        }

        $pdates = array();

        if($longentry > 1) {

          echo '</tr>' . "\n" . '<tr>' . "\n";
        }

        $i = $j - 1;
       
        echo '<td colspan=' . $longentry . '>' . $caption . ' ' . $photocredit . '</td>' . "\n";

        $k++;

        if($k == 7) {



vdeane

  • *
  • *
  • Offline Offline

  • Posts: 10366
  • Age: 28
  • Location: Latham, NY
  • Last Login: October 19, 2019, 10:57:23 PM
    • New York State Roads
Re: AARoads PHP Help
« Reply #1 on: October 06, 2017, 12:47:25 PM »

My guess would be these lines, where it has a second loop in the photos and breaks if it finds one with a different caption:
Code: [Select]
        for($j = $i; $j < $numentries; $j++) {

            if($caption != mysql_result($photodata, $j, "caption")) { break; }

$filename = mysql_result($photodata, $j, "filename");
$datetaken = mysql_result($photodata, $j, "datetaken")
Logged
Please note: All comments here represent my own personal opinion and do not reflect the official position of NYSDOT or its affiliates.

Alex

  • Webmaster
  • *
  • *
  • Offline Offline

  • Posts: 4808
  • Location: Tampa, FL
  • Last Login: October 18, 2019, 06:40:55 AM
    • AARoads
Re: AARoads PHP Help
« Reply #2 on: October 08, 2017, 11:02:26 AM »

Thanks for the feedback Valerie.

Matt was able to figure out the code question yesterday, so we're now able to move forward.

 


Opinions expressed here on belong solely to the poster and do not represent or reflect the opinions or beliefs of AARoads, its creators and/or associates.