JSHINER Posted November 29, 2007 Share Posted November 29, 2007 I was wondering how using this query: function getStuff($db) { $query = 'SELECT item.id AS id, FROM table ORDER BY views DESC LIMIT 51'; return $db->getArray($query); } Can I make it so that only results are returned have a corresponding file so that if "dir/$id.jpg" exists it only returns results with corresponding files. Is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/79460-quick-query-question/ Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 You are not giving us even close to enough information. Do you have another table with a relationship to this one that store the files? If so, give us the table structure of both tables. Quote Link to comment https://forums.phpfreaks.com/topic/79460-quick-query-question/#findComment-402338 Share on other sites More sharing options...
JSHINER Posted November 29, 2007 Author Share Posted November 29, 2007 No just an image elsewhere on the server in a folder that is named via the id. So if the following are returned from the query: 10001 10002 10003 Then only 10001.jpg and 10002.jpg are found on the server, I would like only those two results returned. Quote Link to comment https://forums.phpfreaks.com/topic/79460-quick-query-question/#findComment-402342 Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 Well...I don't think you can get access to that folder via a query. You could possibly do this though <?php if (file_exists("../path/".$row['id'].".jpg")){ //the file exists, display it } else { //the file doesn't exist, so don't display it } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79460-quick-query-question/#findComment-402344 Share on other sites More sharing options...
JSHINER Posted November 29, 2007 Author Share Posted November 29, 2007 Can it be done via the function? Run something on the return... and return a new array of results that have files? Quote Link to comment https://forums.phpfreaks.com/topic/79460-quick-query-question/#findComment-402357 Share on other sites More sharing options...
pocobueno1388 Posted November 29, 2007 Share Posted November 29, 2007 Give this a try <?php function getStuff($db) { $query = 'SELECT item.id AS id FROM table ORDER BY views DESC LIMIT 51'; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ if (file_exists("../path/".$row['id'].".jpg")){ $new_arr[] = $row['id']; } return $new_arr; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79460-quick-query-question/#findComment-402376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.