skip to Main Content

I am having issues with below code which display the news added in the database after few hours, the news is added straight away in the database once created and not sure if i need to make any changes in below code so it fetches the updated

    $query="SELECT *
                FROM
                    (
                    SELECT id,ext,database_id
                    FROM images
                    WHERE database_name='news' AND database_id IN(" . implode(',',array_keys($news)) . ")
                    ORDER BY role
                    ) AS images
                GROUP BY database_id";

2

Answers


  1. I don’t see anything wrong with the script. However, there are few things you might want to consider:

    1. Short tags are not recommended.
      Are PHP short tags acceptable to use?

    2. Using @ suppresses the warnings. You can disable error reporting instead of suppressing the warnings.

    3. Using mysql isn’t recommended. Please use mysqli instead. When should I use MySQLi instead of MySQL?

    Login or Signup to reply.
  2. This query makes no sense:

    SELECT i.*
    FROM (SELECT id, ext, database_id
          FROM images
          WHERE database_name = 'news' AND
                database_id IN (" . implode(',',array_keys($news)) . ")
          ORDER BY role
         ) i
    GROUP BY i.database_id;
    

    You are aggregating by database_id, but using select *. MySQL is hopefully returning an error related to the group by.

    So, you should provide sample data, desired results, and an explanation of what you want to accomplish.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search