brooksh Posted May 23, 2009 Share Posted May 23, 2009 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 More sharing options...
trq Posted May 23, 2009 Share Posted May 23, 2009 Providing fld is a field with which you can sort your rows into order. $sql="SELECT filename FROM images ORDER BY fld DESC LIMIT 3"; Link to comment https://forums.phpfreaks.com/topic/159340-solved-select-a-certain-row-in-a-query/#findComment-840422 Share on other sites More sharing options...
chaking Posted May 23, 2009 Share Posted May 23, 2009 $sql="SELECT filename FROM images WHERE id=$id ORDER BY filename ASC LIMIT 0,2"; ? Link to comment https://forums.phpfreaks.com/topic/159340-solved-select-a-certain-row-in-a-query/#findComment-840424 Share on other sites More sharing options...
brooksh Posted May 23, 2009 Author Share Posted May 23, 2009 I do something different with each photo. So the second image is <img src="<?=$filename?> class="image2" name ="image2"> Link to comment https://forums.phpfreaks.com/topic/159340-solved-select-a-certain-row-in-a-query/#findComment-840428 Share on other sites More sharing options...
trq Posted May 23, 2009 Share Posted May 23, 2009 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"> ? Link to comment https://forums.phpfreaks.com/topic/159340-solved-select-a-certain-row-in-a-query/#findComment-840432 Share on other sites More sharing options...
chaking Posted May 23, 2009 Share Posted May 23, 2009 Already answered -- Link to comment https://forums.phpfreaks.com/topic/159340-solved-select-a-certain-row-in-a-query/#findComment-840437 Share on other sites More sharing options...
brooksh Posted May 23, 2009 Author Share Posted May 23, 2009 Thanks that last one solved it. Sorry, but I searched and couldn't find it a solution. Link to comment https://forums.phpfreaks.com/topic/159340-solved-select-a-certain-row-in-a-query/#findComment-840440 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.