Jump to content

select to array


raduenea

Recommended Posts

I have two tables : one with users and another one with the number of images that they have uploaded.

I mentioned that some images have the option to show or not in the site.

 

I want to show all the users with a picture on every user (take from table 2 if the picture exist), and to show the number of images that he uploaded.

If the user don't have any images uploaded he must not appear.

 

That's why I asked if it's necessary to show all this from an array for a better organization.

 

Please tell me know how can I do that.

Thks

Link to comment
https://forums.phpfreaks.com/topic/260964-select-to-array/#findComment-1337578
Share on other sites

If you do have `user_id` in your `images` table, you can easily get around this by query:

SELECT `images`.`img`, COUNT(`images`.`id`) AS count_img, `users`.*
FROM `images`
LEFT JOIN `users` ON `images`.`user_id` = `users`.`id`
GROUP BY `images`.`user_id`

 

In this way, users who didn't upload any image wouldn't even be included in the return results. Not sure if this is what you're expecting.

Link to comment
https://forums.phpfreaks.com/topic/260964-select-to-array/#findComment-1337684
Share on other sites

The structure of this two tables is:

user table:

- id

- firstname

- lastname

- company

- address

- phone

- email

 

images table:

- id

- user_id

- picture_title

- year

- visible

- picture_path

 

I must notice that the user can hide the pictures. So he can have picture in images table but hide (visible column).

Link to comment
https://forums.phpfreaks.com/topic/260964-select-to-array/#findComment-1337738
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.