Forum Moderators: coopster
<?php
$result=mysql_query("SELECT * FROM gallery_pics ORDER BY pid DESC LIMIT 0, 1");
while ($i = mysql_fetch_array($result)) {
$pics = '<a href="http://www.example.com/albums/'.$i['username'].'/'.$i['file'].'"><img src="http://www.example.com/albums/'.$i['username'].'/resize/'.$i['file'].'?resize(90)"/></a>';
}
$result2=mysql_query("SELECT * FROM gallery_pics ORDER BY pid DESC LIMIT 0, 2");
while ($i = mysql_fetch_array($result2)) {
$pics2 = '<a href="http://www.example.com/albums/'.$i['username'].'/'.$i['file'].'"><img src="http://www.example.com/albums/'.$i['username'].'/resize/'.$i['file'].'?resize(90)"/></a>';
}
$result3=mysql_query("SELECT * FROM gallery_pics ORDER BY pid DESC LIMIT 0, 3");
while ($i = mysql_fetch_array($result3)) {
$pics3 = '<a href="http://www.example.com/albums/'.$i['username'].'/'.$i['file'].'"><img src="http://www.example.com/albums/'.$i['username'].'/resize/'.$i['file'].'?resize(90)"/></a>';
}
$result4=mysql_query("SELECT * FROM gallery_pics ORDER BY pid DESC LIMIT 0, 4");
while ($i = mysql_fetch_array($result4)) {
$pics4 = '<a href="http://www.example.com/albums/'.$i['username'].'/'.$i['file'].'"><img src="http://www.example.com/albums/'.$i['username'].'/resize/'.$i['file'].'?resize(90)"/></a>';
}
?>
<div>
<?php echo $pics?>
<?php echo $pics2?>
<?php echo $pics3?>
<?php echo $pics4?>
</div> As you can see it takes 4 seperate queries. Is there a way to do the same thing in a single query?
<div>
<?php$result=mysql_query("SELECT * FROM gallery_pics ORDER BY pid DESC LIMIT 4");
while ($i = mysql_fetch_array($result)) {
echo '<a href="http://www.example.com/albums/'.$i['username'].'/'.$i['file'].'"><img src="http://www.example.com/albums/'.$i['username'].'/resize/'.$i['file'].'?resize(90)"/></a>';
}?>
</div>
dc
see, the way i have it, i can position any of the pictures any way i want. Your code just spews out a clump of 4 pics (although it does it very efficently).. lol
Another reason id want a variable for each picture is that i'll need this same code on another page to display the last 30 pics and i'll need 3 rows of that. I can't make rows with your code, but i can with mine..
So, is there any way to do the same thing as my code, but in a single query?
I havent used an array because im not sure how. For example, the code below outputs nothing
$result=mysql_query("SELECT * FROM gallery_pics ORDER BY pid DESC LIMIT 6");
$pics = array();
while ($i = mysql_fetch_array($result)) {
$pics[] = '<a href="http://www.example.com/albums/'.$i['username'].'/'.$i['file'].'"><img src="http://www.example.com/albums/'.$i['username'].'/resize/'.$i['file'].'?resize(90)"/></a>';
} and if i try to echo $pics[] i get an error saying i cant use [] for reading.