/    Sign up×
Community /Pin to ProfileBookmark

Logic problem

Hi guys

I have a script that lists through the images links to which are stored in DB, but when the script gets to the final image it does not go back to the first image.

Here’s the actual part that goes through images

[code=php]

/* prepare large images */
if ($num_results > 1) {

$onClick = “”;
for ($k=0; $k<$num_results; $k++) {

$onClickCounter = $k + 1;

/* onclick each row to be hidden execpt current row. Clicking on the current large pic should show the next. When at the end, go back to beginning */
if ($counter == ($onClickCounter -1)) {
// show the next pic
$onClick .= “document.getElementById(‘img-700-$onClickCounter’).style.visibility=’visible’;”;
} else {
// hide all other pics
$onClick .= “document.getElementById(‘img-700-$onClickCounter’).style.visibility=’hidden’;”;
}

/* BUG – to finish – doesn`t show first record again at end
// if last record, set first to visible
if ($onClickCounter == $num_results) {
$onClick .= “document.getElementById(‘img-700-1′).style.visibility=’visible’;”;
$k=0;
}
*/
}

$strLargeImages .= “ntt<div id=”img-700-“.$counter.””>nttt<p class=”img-caption”>$caption</p><p class=”img-caption”>$largeCaption</p><a href=”javascript:popUpImageGallery(‘$productID’)”><img src=””.$path.”700/”.$filename.”” alt=””.$altText.”” title=””.$altText.”” onclick=”$onClick” /></a>ntt</div>”;

} else {
$strLargeImages .= “ntt<div id=”img-700-“.$counter.””>nttt<p class=”img-caption”>$caption</p><p class=”img-caption”>$largeCaption</p><a href=”javascript:popUpImageGallery(‘$productID’)”><img src=””.$path.”700/”.$filename.”” alt=””.$altText.”” title=””.$altText.”” /></a>ntt</div>”;
}
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@FourCourtJesterSep 25.2008 — if ($onClickCounter == $num_results) {
$onClick .= "document.getElementById('img-700-1').style.visibility='visible';";
$k=0;
}


Why is this in the loop? And resetting $k doesn't make it an infinite loop?
Copy linkTweet thisAlerts:
@NightcatauthorSep 25.2008 — That's been comented out, so it doesn't work at the moment. But I need to find a way to nulify variables, I guess.
Copy linkTweet thisAlerts:
@FourCourtJesterSep 25.2008 — Ok well, based on your code, you want your images to roll back to the first image.

What do you need it to reset back to the first image for? is it for $strLargeImages ? Because you use a $counter variable thats not modified anywhere in this code snippet. is $counter supposed to be $k?
Copy linkTweet thisAlerts:
@NightcatauthorSep 25.2008 — I'm fixing somebody elses scripts at the moment, so I messed up copying the script, not sure that'll be enough, but to copy the whole script, will be a couple of thousand lines.

[code=php]
$result = mysql_query($qry);
$num_results = mysql_num_rows($result);

if ($num_results > 0) {

/* Limit to GALLERY_LIMIT */
if ($num_results > GALLERY_LIMIT) {
$num_results = GALLERY_LIMIT;
}

for ($i=0; $i<$num_results; $i++) {

$counter = $i+1;

$row = mysql_fetch_array($result);

$path = $row['fldPath'];
$filename = $row['fldFilename'];
$caption = $row['fldCaption'];
$largeCaption = $row['fldCaptionLrg'];
$altText = $row['fldAlt'];

/* prepare large images */
if ($num_results > 1) {

$onClick = "";
for ($k=0; $k<$num_results; $k++) {

$onClickCounter = $k + 1;

/* onclick each row to be hidden execpt current row. Clicking on the current large pic should show the next. When at the end, go back to beginning */
if ($counter == ($onClickCounter -1)) {
// show the next pic
$onClick .= "document.getElementById('img-700-$onClickCounter').style.visibility='visible';";
} else {
// hide all other pics
$onClick .= "document.getElementById('img-700-$onClickCounter').style.visibility='hidden';";
}


/* BUG - to finish - doesn`t show first record again at end
// if last record, set first to visible
if ($onClickCounter == $num_results) {
$onClick .= "document.getElementById('img-700-1').style.visibility='visible';";
$k=0;
}
*/
}

$strLargeImages .= "ntt<div id="img-700-".$counter."">nttt<p class="img-caption">$caption</p><p class="img-caption">$largeCaption</p><a href="javascript:popUpImageGallery('$productID')"><img src="".$path."700/".$filename."" alt="".$altText."" title="".$altText."" onclick="$onClick" /></a>ntt</div>";

} else {
$strLargeImages .= "ntt<div id="img-700-".$counter."">nttt<p class="img-caption">$caption</p><p class="img-caption">$largeCaption</p><a href="javascript:popUpImageGallery('$productID')"><img src="".$path."700/".$filename."" alt="".$altText."" title="".$altText."" /></a>ntt</div>";
}
[/code]
Copy linkTweet thisAlerts:
@NightcatauthorSep 30.2008 — While I'm still on this case, here's another question.

Does anyone know any simple php picture galeries that I could may be pull appart and see how they work? I already tried a couple, but they were not exactly simple ?

I'll keep trying though.
×

Success!

Help @Nightcat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...