Jump to content

[SOLVED] Select A Certain Row in a query


brooksh

Recommended Posts

I'm not even sure if this is possible, but I want to display the first,second and third photo in my database. How could I do this? If it is possible, I know it probably won't be using while.

 

$sql="SELECT filename FROM images WHERE id=$id";
$result = mysql_query ($sql);
while($row = mysql_fetch_array ($result, MYSQL_ASSOC))
{
$file_name = $row[file_name];
}//end while
echo $file_name[1];
echo $file_name[2];
echo $file_name[3];

 

 

Link to comment
https://forums.phpfreaks.com/topic/159340-solved-select-a-certain-row-in-a-query/
Share on other sites

So maybe you want something like....

 

<?php
$sql = "SELECT filename FROM images ORDER BY fld DESC LIMIT 3";
if ($result = mysql_query ($sql)) {
  if (mysql_num_rows($result)) {
    $arr = array();
    while($row = mysql_fetch_assoc($result)) {
      $arr[] = $row['filename'];
    }
  }
}
?>
<img src="<?=$arr[0]?>" class="image1" name ="image1">
<img src="<?=$arr[1]?>" class="image2" name ="image2">
<img src="<?=$arr[2]?>" class="image3" name ="image3">

 

?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.