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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.