News:

Thanks to everyone for the feedback on what errors you encountered from the forum database changes made in Fall 2023. Let us know if you discover anymore.

Main Menu

AARoads PHP Help

Started by Alex, October 06, 2017, 08:31:19 AM

Previous topic - Next topic

Alex

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.

$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

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:

        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")
Please note: All comments here represent my own personal opinion and do not reflect the official position of NYSDOT or its affiliates.

Alex

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.