How i can get last posts sql
SELECT id,name,image FROM posts order by ID DESC LIMIT 5;
and get every string deferent style
like:
image from Column1 $row[0] biggest size
image from Column2.$row[0], Column3.$row[0] ... fixed size
CodePudding user response:
The first row is 0 as rows always start from 0,1,2...
So what i did here, while going through fetched rows, i have used an if else statement, where i check if the row is equal to 0 then it means its the first row, else you have other rows 1,2,3... etc.
$query = "SELECT id,name,image FROM posts order by ID DESC LIMIT 5";
while ($f = mysqli_fetch_array($query)) {
$row = 0;
if ($row == 0) {
//your first post here
$row ;
}else{
// your other posts
}
}
CodePudding user response:
i use your code to fix it like that:
$query = "SELECT id,name,image FROM posts order by ID DESC LIMIT 5";
$i = 0;
while ($f = mysqli_fetch_array($query)) {
$i ;
if ($i == 1) {
echo"$f[2] -large<br>";
}else{
echo"$f[2] -small<br>";
}
}