/    Sign up×
Community /Pin to ProfileBookmark

Image album. the select doesnt work?

Im trying to make a album with next/previous image. The first image(else statement) shows but the image url doesnt get switched when i press next/last.How can i solve this?

[code=php]
$next= $_POST[‘next’];
$last= $_POST[‘last’];

if($last== “last” ){
$result=mysqli_query($con, “SELECT * FROM album WHERE user_id=’$id’ AND (time_added>’$time’) LIMIT 1”);
$row=mysqli_fetch_array($result);
$time = $row[‘time_added’]; //Y-m-d H:i:s
$url = $row[‘img_url’];
}
else if($next== “next”){
$result=mysqli_query($con, “SELECT * FROM album WHERE user_id=’$id’ ORDER BY time_added DESC AND (time_added<‘$time’) LIMIT 1”);
$row=mysqli_fetch_array($result);
$time = $row[‘time_added’];
$url = $row[‘img_url’];
}
else{
$result=mysqli_query($con, “SELECT * FROM album WHERE user_id=’$id’ ORDER BY time_added DESC LIMIT 1”);
$row=mysqli_fetch_array($result);
$url = $row[‘img_url’];
$time = $row[‘time_added’];
}
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 18.2015 — I don't understand the first two lines: the value of $img from the first line will [i]always[/i] be overwritten by the value from the second line. I'm guessing that's not what you really want to do?
Copy linkTweet thisAlerts:
@jag1authorNov 18.2015 — ops i edited that

thanks
Copy linkTweet thisAlerts:
@jag1authorNov 20.2015 — I have edited my code so it works pretty well, i can change image both previous and next.

I think im halfway there but i dont know how to get it all to work.

Seems like there are 2 things that doesnt work which i dont really know how to solve:

The first next and the first last image doesnt get the $url so the <img> is <img src="folder/"> instead of <img src="folder/image1.jpg">

The second thing is i dont know how to stop the next/previous image if there is no row in the db that is < or > than the $time.

I hope that someone can help me

[code=php]

<?php
$next = $_POST['next'];
$nextValue = $_POST['nextvalue'];
$last = $_POST['last'];
$lastvalue = $_POST['lastvalue'];

if($next == "next"){

$result=mysqli_query($con, "SELECT * FROM album WHERE user_id='$id' AND (time_added<'$nextValue') LIMIT 1");
$row=mysqli_fetch_array($result);
$time = $row['time_added'];
$url = $row['img_url'];

}
else if($last == "last"){
$result=mysqli_query($con, "SELECT * FROM album WHERE user_id='$id' AND (time_added>'$lastvalue') LIMIT 1");
$row=mysqli_fetch_array($result);
$time = $row['time_added'];
$url = $row['img_url'];
}
else{
$result=mysqli_query($con, "SELECT * FROM album WHERE user_id='$id' ORDER BY time_added DESC LIMIT 1");
$row=mysqli_fetch_array($result);

$time = $row['time_added'];
$url = $row['img_url'];

}

?>

<form action='' method='post'>

<input type="hidden" id="next" name='next' value="next">
<input type="hidden" id="next" name='nextvalue' value="<?php echo $time; ?>">


</form>

<form action='' method='post'>
<input type="hidden" id="last" name='last' value="last">
<input type="hidden" id="last" name='lastvalue' value="<?php echo $time; ?>">

</form>

[/code]
×

Success!

Help @jag1 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.18,
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,
)...