Jump to content

Quick Query Question


JSHINER

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/79460-quick-query-question/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/79460-quick-query-question/#findComment-402342
Share on other sites

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
}

?>

Link to comment
https://forums.phpfreaks.com/topic/79460-quick-query-question/#findComment-402344
Share on other sites

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;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/79460-quick-query-question/#findComment-402376
Share on other sites

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.